﻿using Bandit.Helpers;
using Bandit.UI;
using ETC.DLEDLightingSystemPlus.Core;
using ETC.DLEDLightingSystemPlus.Helpers;
using ETC.DLEDLightingSystemPlus.Models;
using ETC.DLEDLightingSystemPlus.ViewModels;
using ETC.DLEDLightingSystemPlus.Windows;
using Renci.SshNet.Security;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
//using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ETC.DLEDLightingSystemPlus.UserControls
{
    /// <summary>
    /// UcTestStation.xaml 的交互逻辑
    /// </summary>
    public partial class UcTestStation : UserControl
    {

        public delegate void StartTestResultHandler(TestStation testStation, string TestResult);
        public event StartTestResultHandler OnStartTestResultChanged;

        public delegate void PowerOFFTestResultHandler(TestStation testStation, string PowerOFFResult);
        public event PowerOFFTestResultHandler OnPowerOFFTestResultChanged;

        //public delegate void ScanBarcodeHandler(TestStation testStation);
        //public event ScanBarcodeHandler OnScanBarcodeChanged;

        //public delegate void AOITestResultHandler(string AOIResult);
        //public event AOITestResultHandler OnAOITestResultChanged;

        //public delegate void ACTestResultHandler(string AOIResult);
        //public event AOITestResultHandler OnACTestResultChanged;

        //public delegate void NTCTestResultHandler(string AOIResult);
        //public event AOITestResultHandler OnNTCTestResultChanged;

        #region 构造函数

        public UcTestStation()
        {
            InitializeComponent();

            this.Loaded += delegate
            {
                //串口初始化
                this.InitMiniLedLightUpSerialPort();

                this.rtxtTestData.Document.Blocks.Clear();
            };

        }

        public TestStation TestStation
        {
            get
            {
                TestStation result = null;

                this.ThreadSafe(delegate
                {
                    result = this.DataContext as TestStation;
                }, false);

                return result;
            }
        }

        private TestInfo TestInfo
        {
            get
            {
                return this.TestStation.TestInfo;
            }
        }

        private ConfigInfo ConfigInfo
        {
            get
            {
                return this.TestStation.ConfigInfo;
            }
        }

        public bool IsEngineer = false;

        public bool IsMultiStationStart = false;

        private DLEDLightingHelper DLEDLightingHelper
        {
            get
            {
                if (this.TestStation == null)
                {
                    return null;
                }

                return this.TestStation.DLEDLightingHelper;
            }
        }

        #endregion

        #region OnClick Event
        private void BanditButton_Click(object sender, RoutedEventArgs e)
        {
            if (sender is Control ctl && ctl.Tag != null)
            {
                switch (ctl.Tag.ToString())
                {
                    case "StartTest":

                        IsMultiStationStart = false;

                        this.StartTest();

                        break;
                    case "ResetCount":
                        if (this.ShowDialog("是否确认重置测试计数?", "提示", MessageBoxButton.OKCancel, Bandit.UI.DialogIcon.OK) == MessageBoxResult.OK)
                        {
                            TestInfo.Pass = 0;
                            TestInfo.Fail = 0;
                            TestInfo.Total = 0;
                        }
                        break;
                    case "DeleteStation":
                        {
                            if (this.ShowDialog("Are you sure to delete?", App.PromptText, MessageBoxButton.YesNo, Bandit.UI.DialogIcon.QuestionFace) == MessageBoxResult.Yes)
                            {
                                this.DeleteStation(true);
                            }
                        }
                        break;
                    case "SettingStation":
                        {
                            FrmConfig frm = new FrmConfig(this.TestStation, true);

                            if (frm.ShowDialog().Value)
                            {

                                Console.WriteLine("config baocun");
                            }
                            else
                            {
                                Console.WriteLine("加载中...");

                                if (!File.Exists(this.GetBaseDirectory() + "Configs\\" + TestStation.StationInfo.TestConfigFile))
                                {

                                    return;
                                }

                                this.TestStation.ConfigInfo.TestConfig = Bandit.Helpers.ConfigHelper.XmlFileDeserialize<TestConfig>(this.GetBaseDirectory() + "Configs\\" + TestStation.StationInfo.TestConfigFile);

                                this.TestStation.InitTestItemResult();

                                this.TestStation.LoadLEDInterface();

                            }

                        }
                        break;

                    case "ShowEditStation":
                        {
                            preComPort = this.TestStation.StationInfo.ComPort;

                            ShowStationEdiePanel();

                        }
                        break;
                    case "SearchPortNames":
                        {
                            this.TestStation.LoadPortNames();
                        }
                        break;
                    case "EditStation":
                        {
                            EditStation();
                        }
                        break;
                    case "CancelEditStation":
                        {
                            HideStationEditPanel();
                        }
                        break;
                    case "StopTest":
                        {
                            if (TestStation.IsStop)
                            {
                                TestStation.IsStop = false;

                                this.Loading.Show("即将结束测试");
                            }
                        }
                        break;
                    case "ImportStationConfig":
                        {

                            Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
                            //ofd.InitialDirectory = System.IO.Path.Combine(this.GetBaseDirectory(), "Configs");
                            ofd.Filter = "Config|*" + App.TestConfigFileExtension;
                            if (ofd.ShowDialog().Value)
                            {
                                string fileName = ofd.FileName;

                                string relativePath = System.IO.Path.GetFileName(fileName);

                                if (this.TestStation.StationInfo.TestConfigFile != relativePath)
                                {
                                    //更新站点配置文件
                                    this.TestStation.StationInfo.TestConfigFile = relativePath;

                                    //保存站点信息
                                    App.MainViewModel.SaveStations();

                                    this.ShowPromptWindow("保存成功，自动重启中...");

                                    System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);

                                    Application.Current.Shutdown();

                                }
                                else
                                {
                                    this.ShowPromptWindow("选择的文件跟原来一致");
                                }
                            }
                        }
                        break;
                    case "CheckUSBTest":
                        {
                            this.Loading.Show("USB Check");

                            this.rtxtTestData.Document.Blocks.Clear();

                            Task.Factory.StartNew(() =>
                            {
                                if (!SetModel())
                                {
                                    return;
                                }

                                DLEDLightingHelper.GetAllLEDTestData(0);

                            }).ContinueWith(t =>
                            {
                                DLEDLightingHelper.PowerOff();
                                this.Loading.Hide();
                            });
                        }
                        break;
                    default:
                        break;
                }
            }
        }

        #endregion

        #region Edit Station
        private void ShowStationEdiePanel()
        {
            this.ucPanelStationEdit.Show(0.3, delegate
            {
                this.txtEditStationName.Focus();
            });
        }

        private void HideStationEditPanel()
        {
            this.ucPanelStationEdit.Hide(0.3, delegate
            {
                //this.txtEditStationName.Clear();

            });
        }
        string preComPort = string.Empty;

        private void EditStation()
        {
            if (string.IsNullOrWhiteSpace(this.txtEditStationName.Text))
            {
                this.ShowDialogByPlease("Please input station name.");
                this.txtEditStationName.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(TestStation.StationInfo.ComPort))
            {
                this.ShowDialogByPlease("Please Select PortName.");

                return;
            }
            try
            {
                if (this.TestStation.ConfigInfo != null && this.TestStation.StationInfo.ComPort != preComPort)
                {

                    if (this.TestStation.StationInfo.ComPort != "Com999")
                    {
                        //判断一下选择 的Com号是否已经选过了。
                        if (App.MainViewModel.TestStations.Where(s => s.StationInfo.ComPort == this.TestStation.StationInfo.ComPort).Count() > 1)
                        {

                            this.ShowDialogByPlease("Please Select Other PortName,this is Exist");

                            return;

                        }
                    }

                    App.MainViewModel.SaveStations();

                    this.ShowDialog("COM更改，程序重启", "提示");

                    System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);

                    Application.Current.Shutdown();
                }

                this.HideStationEditPanel();


            }
            catch (Exception ex)
            {
                Bandit.Helpers.LogHelper.Error(ex, "EditStation");
                this.ShowDialog(ex.Message, "Error", MessageBoxButton.OK, DialogIcon.Error);
            }
        }


        private void DeleteStation(bool isRefresh)
        {
            this.TestStation.DLEDLightingHelper.OnConnectedChanged -= Instance_OnConnectedChanged;

            App.MainViewModel.RemoveStation(TestStation, isRefresh);

            TestStation.Dispose();
        }

        #endregion

        #region 初始化测试项
        private void InitTestItemResult()
        {
            foreach (TestItemResult testItemResult in TestInfo.TestItemResults)
            {
                testItemResult.DicResult = null;
                testItemResult.Remark = "";
                testItemResult.ResultValue = "";
                testItemResult.Result = "";
            }

            foreach (DIYLedModel dIYLedModel in TestStation.LedModelList)
            {

                dIYLedModel.LedType = "Idle";

            }
        }
        #endregion

        #region 开始测试

        //public void PowerOFFLed(bool isSuccess,out string PowerOFFResult)
        //{
        //    AppendTestData("关闭电源", MyBrushes.Green);
        //    PowerOFFResult = DLEDLightingHelper.PowerOff();
        //    AppendTestData("结束测试", MyBrushes.Green);
        //    FinishTest(!TestStation.IsStop, isSuccess);
        //}

        public void PowerOFFLed()
        {
            AppendTestData("关闭电源", MyBrushes.Green);
            string r = DLEDLightingHelper.PowerOff();
            AppendTestData("结束测试", MyBrushes.Green);

            TestStation.IsStop = false;

            this.Loading.Hide();

            if (!ConfigHelper.GetValueToBoolean("IsPLCDebug"))
            {
                if (string.IsNullOrEmpty(r) && OnPowerOFFTestResultChanged != null)
                {
                    OnPowerOFFTestResultChanged(this.TestStation, "Fail");
                }
                else
                {
                    OnPowerOFFTestResultChanged(this.TestStation, "Pass");
                }
            }
        }

        public void StartTest()
        {
            //if (TestStation.TestInfo.StationName.Contains("NTC"))
            //{
            //if (OnScanBarcodeChanged != null)
            //{
            //    OnScanBarcodeChanged(this.TestStation);
            //}
            //} 

            LogHelper.Info("1[" + TestInfo.Barcode + "]");
            TestInfo.Barcode += "\r\n";
            TestInfo.Barcode = TestInfo.Barcode.Trim().Replace("\n","").Replace("\r","");

            LogHelper.Info("2[" + TestInfo.Barcode + "]");
            try
            {
                bool IsCheckSuccess = true;

                if (string.IsNullOrEmpty(TestInfo.Barcode))
                {
                    //this.ShowDialog(App.GetString("BarcodeNullPrompt"), App.GetString("Prompt"), MessageBoxButton.OK, DialogIcon.Warning);
                    this.ShowPromptWindow(App.GetString("BarcodeNullPrompt"), PromptType.Red);

                    IsCheckSuccess = false;
                }


                if (!this.TestInfo.EnabledStartButton)
                {
                    //this.ShowDialog(App.GetString("EnginerModePrompt"), App.GetString("Prompt"), MessageBoxButton.OK, DialogIcon.Warning);
                    this.ShowPromptWindow(App.GetString("EnginerModePrompt"), PromptType.Red);
                    IsCheckSuccess = false;
                }

                if (IsEngineer)
                {
                    //this.ShowDialog(App.GetString("EnginerModePrompt"), App.GetString("Prompt"), MessageBoxButton.OK, DialogIcon.Warning);
                    this.ShowPromptWindow(App.GetString("EnginerModePrompt"), PromptType.Red);
                    IsCheckSuccess = false;
                }


                TestStation.IsStop = true;
                //TestStation.IsPowerOFF = false;

                if (!IsCheckSuccess)
                {
                    TestStation.IsStop = false;

                    if (OnStartTestResultChanged != null)
                    {
                        OnStartTestResultChanged(this.TestStation, !TestStation.IsStop ? "Stop" : "false");

                        if (TestStation.TestInfo.StationName.Contains("NTC"))
                        {
                            //NTC 测试完自动关灯
                            PowerOFFLed();
                        }
                    }
                    return;
                }

                InitTestItemResult();

                this.rtxtTestData.Document.Blocks.Clear();

                //测试开始，更新界面显示
                TestStation.TestInfo.TestStart();

                //更新状态栏显示
                TestStation.Status.Update("Testing...", MyBrushes.RichYellow);

                if (!IsMultiStationStart)
                {
                    this.Loading.Show("Testing...");
                }

                bool isSuccess = true;
                vledCloseCurrent = 0;
                Task.Factory.StartNew(() =>
                {

                    //if (ConfigInfo.TestConfig.Station == "AC#2")
                    //{
                    //    Thread.Sleep(ConfigHelper.GetValueToInt("ACCmdDelay2",400));
                    //    LogHelper.Info($"AC#2工位延时{ConfigHelper.GetValueToInt("ACCmdDelay2", 400)}ms");
                    //}
                    //if (ConfigInfo.TestConfig.Station == "AOI#2")
                    //{
                    //    Thread.Sleep(ConfigHelper.GetValueToInt("AOICmdDelay2", 400));
                    //    LogHelper.Info($"AOI#2工位延时{ConfigHelper.GetValueToInt("AOICmdDelay2", 400)}ms");
                    //}
                    //if (ConfigInfo.TestConfig.Station == "NTC#2")
                    //{
                    //    Thread.Sleep(ConfigHelper.GetValueToInt("NTCCmdDelay2", 400));
                    //    LogHelper.Info($"NTC#2工位延时{ConfigHelper.GetValueToInt("NTCCmdDelay2", 400)}ms");
                    //}

                    isSuccess = this.SetModel();

                    if (!isSuccess)
                    {

                        return;
                    }

                    int processIcount = TestInfo.TestItemResults.Count(x => x.IsTest);

                    foreach (TestItemResult testItemResult in TestInfo.TestItemResults)
                    {
                        if (!TestStation.IsStop)
                        {
                            return;
                        }

                        if (testItemResult.IsTest)
                        {
                            TestInfo.Progress += 90 / processIcount;

                            AppendTestData(string.Format("{0}-{1} 开始测试", testItemResult.Num, testItemResult.Name), MyBrushes.RichYellow);

                            testItemResult.Result = "Testing";

                            #region Pin短路开路测试
                            if (testItemResult.TestItemCode == "PINShortOpenTest")
                            {
                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetPinOSTestData());

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    //this.ShowDialog("Pin短路开路测试异常,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        this.ShowPromptWindow("Pin短路开路测试异常,结束测试", PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }
                            }
                            #endregion

                            #region NTC极性测试
                            if (testItemResult.TestItemCode == "DiodePolarityTest")
                            {
                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetDiodePolarity());

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    //this.ShowDialog("Pin短路开路测试异常,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        this.ShowPromptWindow("NTC极性测试异常,结束测试", PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }
                            }
                            #endregion

                            #region 常温下热敏电阻测试
                            if (testItemResult.TestItemCode == "ThermistorTestingRoomTemperature")
                            {
                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetNTCData());

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        //this.ShowDialog("常温下热敏电阻测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                        this.ShowPromptWindow("常温下热敏电阻测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }
                            }
                            #endregion

                            #region 芯片待机电流
                            if (testItemResult.TestItemCode == "ChipStandbyCurrent")
                            {
                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetLEDDriverICStandbyVolCurData());

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        //this.ShowDialog("芯片待机电流测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                        this.ShowPromptWindow("芯片待机电流测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }

                            }
                            #endregion

                            #region IFBDataTest
                            if (testItemResult.TestItemCode == "IFBDataTest")
                            {

                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetIFBData());

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        //this.ShowDialog("芯片正常运行电流测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                        this.ShowPromptWindow("IFB电流测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }

                            }
                            #endregion

                            #region 芯片正常运行电流
                            if (testItemResult.TestItemCode == "ChipWorkingCurrent")
                            {
                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetLEDDriverICWorkingVolCurData());

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        //this.ShowDialog("芯片正常运行电流测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                        this.ShowPromptWindow("芯片正常运行电流测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }

                            }
                            #endregion

                            #region 10uA电流测试 OpenShort
                            if (testItemResult.TestItemCode == "CurrentTest10uA")
                            {
                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetUATestData());

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        //this.ShowDialog("10uA电流测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                        this.ShowPromptWindow("OpenShort电流测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }

                                if (testItemResult.DicResult != null)
                                {
                                    foreach (var item in testItemResult.DicResult)
                                    {
                                        AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichYellow);
                                    }
                                }

                            }
                            #endregion

                            #region VLED亮度全关的漏电流
                            if (testItemResult.TestItemCode == "VLEDFullyClosedCurrent")
                            {

                                this.SetMCDCBCScaleForTestItem(testItemResult);

                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetAllLEDTestData(testItemResult.SetCurrentValue));

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        //this.ShowDialog("VLED亮度全关的漏电流测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                        this.ShowPromptWindow("VLED亮度全关的漏电流测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }

                            }
                            #endregion

                            #region 单路LED低、高电流
                            if (testItemResult.TestItemCode == "SingleLEDLowCurrent" || testItemResult.TestItemCode == "SingleLEDHighCurrent")
                            {
                                this.SetMCDCBCScaleForTestItem(testItemResult);

                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetSingleLEDTestData(testItemResult.SetCurrentValue));

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;

                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        if (testItemResult.TestItemCode == "SingleLEDLowCurrent")
                                        {
                                            //this.ShowDialog("单路LED低电流测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                            this.ShowPromptWindow("单路LED低电流测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                            AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        }
                                        else
                                        {
                                            //this.ShowDialog("单路LED高电流测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                            this.ShowPromptWindow("单路LED高电流测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                            AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        }

                                        return;
                                    }
                                }

                                if (testItemResult.DicResult != null)
                                {
                                    foreach (var item in testItemResult.DicResult)
                                    {
                                        if (item.Key == "CMD" || item.Key == "result")
                                        {
                                            continue;
                                        }

                                        string currentStr = item.Value.ToString().Split(",")[1].Replace("mA", "");

                                        double dCurrentValue = Convert.ToDouble(currentStr);

                                        if (dCurrentValue <= testItemResult.Limit.Upper && dCurrentValue >= testItemResult.Limit.Lower)
                                        {
                                            AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichGreen);
                                        }
                                        else
                                        {
                                            AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichRed);
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region LED单芯片回路低、高电流
                            if (testItemResult.TestItemCode == "LEDSingleICLowCurrent" || testItemResult.TestItemCode == "LEDSingleICHighCurrent")
                            {
                                this.SetMCDCBCScaleForTestItem(testItemResult);

                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetICLEDTestData(testItemResult.SetCurrentValue));

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;

                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        if (testItemResult.TestItemCode == "LEDSingleICLowCurrent")
                                        {
                                            //this.ShowDialog("LED单芯片回路低电流测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                            this.ShowPromptWindow("LED单芯片回路低电流测试Fail,结束测试", PromptType.Red, 5, 0.2);

                                            AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        }
                                        else
                                        {
                                            //this.ShowDialog("LED单芯片回路高电流测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                            this.ShowPromptWindow("LED单芯片回路高电流测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                            AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        }
                                        return;
                                    }
                                }

                                if (testItemResult.DicResult != null)
                                {
                                    foreach (var item in testItemResult.DicResult)
                                    {
                                        double dCurrentValue = (double)(item.Value);

                                        if (dCurrentValue <= testItemResult.Limit.Upper && dCurrentValue >= testItemResult.Limit.Lower)
                                        {
                                            AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichGreen);
                                        }
                                        else
                                        {
                                            AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichRed);
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region 全画面低、高电流
                            if (testItemResult.TestItemCode == "FullScreenLowCurrent" || testItemResult.TestItemCode == "FullScreenHighCurrent")
                            {
                                this.SetMCDCBCScaleForTestItem(testItemResult);

                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetAllLEDTestData(testItemResult.SetCurrentValue));

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        if (testItemResult.TestItemCode == "FullScreenLowCurrent")
                                        {
                                            //this.ShowDialog("全画面低电流测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                            this.ShowPromptWindow("全画面低电流测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                            AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        }
                                        else
                                        {
                                            //this.ShowDialog("全画面高电流测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                            this.ShowPromptWindow("全画面高电流测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                            AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        }
                                        return;
                                    }
                                }

                            }
                            #endregion

                            #region 点灯后热敏电阻测试
                            if (testItemResult.TestItemCode == "ThermistorTestingLightingTemperature")
                            {
                                this.SetMCDCBCScale();

                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetNTCData());

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        //this.ShowDialog("点灯后热敏电阻测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                        this.ShowPromptWindow("点灯后热敏电阻测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }
                            }
                            #endregion

                            #region 棋盘LED
                            if (testItemResult.TestItemCode == "QiPanPattenDisplay")
                            {
                               
                                if (ConfigInfo.TestConfig.RootQiPanLedModelList.Count > 0)
                                {
                                    this.SetMCDCBCScaleForDIY();

                                    if (ConfigInfo.TestConfig.TestCaseType == 6 || ConfigInfo.TestConfig.TestCaseType == 4)
                                    {
                                        //DLEDLightingHelper.DIYStart();
                                        foreach (RootDIYLedModel rootDIYLedModel in ConfigInfo.TestConfig.RootQiPanLedModelList)
                                        {
                                            if (rootDIYLedModel.IsTest)
                                            {
                                                testItemResult.Result = "Testing";

                                                AppendTestData(string.Format("棋盘格 图案：{0}", rootDIYLedModel.RootName), MyBrushes.Green);
                                                //排序
                                                List<IGrouping<string, DIYLedModel>> dIYLedModelICGroup = rootDIYLedModel.DiyLedModelList.GroupBy(t => t.ICID).ToList();

                                                foreach (IGrouping<string, DIYLedModel> ICGroup in dIYLedModelICGroup)
                                                {
                                                    string IC = ICGroup.Key;

                                                    List<IGrouping<string, DIYLedModel>> dIYLedModelScanNumGroup = ICGroup.GroupBy(t => t.Scan_num).ToList();

                                                    foreach (IGrouping<string, DIYLedModel> ScanNumGroup in dIYLedModelScanNumGroup)
                                                    {
                                                        string ScanNum = ScanNumGroup.Key;

                                                        List<DIYLedModel> dIYLedModels = ScanNumGroup.OrderBy(a => a.LEDID).ToList();

                                                        int foregroundLight = 0;
                                                        int backgroundLight = 0;

                                                        int LedCount = ConfigInfo.TestConfig.IC_PinCount;

                                                        string LedData = "";

                                                        for (int indexLed = 1; indexLed < LedCount + 1; indexLed++)
                                                        {
                                                            DIYLedModel dIYLedModel = dIYLedModels.FirstOrDefault(s => s.LEDID == indexLed);

                                                            if (dIYLedModel == null)
                                                            {
                                                                LedData += " " + backgroundLight.ToString();
                                                            }
                                                            else
                                                            {
                                                                foregroundLight = dIYLedModel.LightValue;

                                                                if (dIYLedModel.IsFlag == Visibility.Visible)
                                                                {
                                                                    if (dIYLedModel.LedType == "Nomal")
                                                                    {
                                                                        LedData += " " + foregroundLight.ToString();
                                                                    }
                                                                    else
                                                                    {
                                                                        LedData += " " + foregroundLight.ToString();
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        DLEDLightingHelper.SetDIYPictureData(IC, ScanNum, LedData);
                                                    }

                                                }

                                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.showDIYPicture(0));

                                                if (!JudgeTestResult(testItemResult))
                                                {
                                                    isSuccess = false;

                                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                                    {
                                                        //this.ShowDialog("DIY 图案测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                                        this.ShowPromptWindow("棋盘格 图案测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                                        return;
                                                    }
                                                }

                                                Thread.Sleep(ConfigInfo.TestConfig.DIYPictureDelayTimeMs);
                                            }

                                        }
                                        //DLEDLightingHelper.DIYEnd();
                                    }
                                    else
                                    {
                                        foreach (RootDIYLedModel rootDIYLedModel in ConfigInfo.TestConfig.RootQiPanLedModelList)
                                        {
                                            if (rootDIYLedModel.IsTest)
                                            {
                                                AppendTestData(string.Format("棋盘格 图案：{0}", rootDIYLedModel.RootName), MyBrushes.Green);
                                                //排序
                                                List<IGrouping<string, DIYLedModel>> dIYLedModelGroup = rootDIYLedModel.DiyLedModelList.GroupBy(t => t.ICID).ToList();

                                                foreach (IGrouping<string, DIYLedModel> group in dIYLedModelGroup)
                                                {
                                                    string IC = group.Key;

                                                    string Led = "";

                                                    int i = 0;

                                                    List<DIYLedModel> dIYLedModels = group.OrderBy(a => a.LEDID).ToList();

                                                    int foregroundLight = 0;
                                                    int backgroundLight = 128;

                                                    int LedCount = ConfigInfo.TestConfig.IC_PinCount;

                                                    //if (ConfigInfo.TestConfig.TestModelCode == 1 || ConfigInfo.TestConfig.TestModelCode == 8 || ConfigInfo.TestConfig.TestModelCode == 9 || ConfigInfo.TestConfig.TestModelCode == 11)
                                                    //{
                                                    //    LedCount = 16;
                                                    //}
                                                    //else
                                                    //{
                                                    //    LedCount = 48;
                                                    //}

                                                    for (int indexLed = 1; indexLed < LedCount + 1; indexLed++)
                                                    {
                                                        DIYLedModel dIYLedModel = dIYLedModels.FirstOrDefault(s => s.LEDID == indexLed);

                                                        if (dIYLedModel == null)
                                                        {
                                                            Led += " " + backgroundLight.ToString();
                                                        }
                                                        else
                                                        {
                                                            foregroundLight = dIYLedModel.LightValue;

                                                            if (dIYLedModel.IsFlag == Visibility.Visible)
                                                            {
                                                                if (dIYLedModel.LedType == "Nomal")
                                                                {
                                                                    Led += " " + foregroundLight.ToString();
                                                                }
                                                                else
                                                                {
                                                                    Led += " " + foregroundLight.ToString();
                                                                }
                                                            }
                                                        }
                                                    }
                                                    if (ConfigInfo.TestConfig.TestCaseType == 1 || ConfigInfo.TestConfig.TestCaseType == 3 || ConfigInfo.TestConfig.TestCaseType == 4 || ConfigInfo.TestConfig.TestCaseType == 5)
                                                    {
                                                        DLEDLightingHelper.SetDIYPictureData(IC, Led);
                                                    }
                                                    else
                                                    {
                                                        DLEDLightingHelper.SetCheckerBoardPictureData(IC, Led);
                                                    }
                                                }

                                                if (ConfigInfo.TestConfig.TestCaseType == 1 || ConfigInfo.TestConfig.TestCaseType == 3 || ConfigInfo.TestConfig.TestCaseType == 4 || ConfigInfo.TestConfig.TestCaseType == 5)
                                                {
                                                    testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.showDIYPicture(0));
                                                }
                                                else
                                                {
                                                    testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.ShowCheckerBoardPicture(ConfigInfo.TestConfig.DIYPictureSetValue));
                                                }

                                                if (!JudgeTestResult(testItemResult))
                                                {
                                                    isSuccess = false;
                                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                                    {
                                                        //this.ShowDialog("棋盘格 图案测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                                        this.ShowPromptWindow("棋盘格 图案测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                                        return;
                                                    }
                                                }

                                                Thread.Sleep(ConfigInfo.TestConfig.DIYPictureDelayTimeMs);
                                            }

                                        }

                                    }
                                }
                                else
                                {
                                    testItemResult.ResultValue = "Success";
                                    testItemResult.Result = "Pass";
                                    AppendTestData(string.Format("{0}-{1} 成功", ">>>", testItemResult.Name), MyBrushes.Green);
                                }
                                    
                            }
                            #endregion

                            #region DIYLED
                            if (testItemResult.TestItemCode == "DIYPattenDisplay")
                            {
                                if (ConfigInfo.TestConfig.RootDiyLedModelList.Count > 0)
                                {
                                    this.SetMCDCBCScaleForDIY();

                                    if (ConfigInfo.TestConfig.TestCaseType == 6 || ConfigInfo.TestConfig.TestCaseType == 4)
                                    {
                                        //DLEDLightingHelper.DIYStart();
                                        foreach (RootDIYLedModel rootDIYLedModel in ConfigInfo.TestConfig.RootDiyLedModelList)
                                        {
                                            if (rootDIYLedModel.IsTest)
                                            {
                                                testItemResult.Result = "Testing";

                                                AppendTestData(string.Format("DIY 图案：{0}", rootDIYLedModel.RootName), MyBrushes.Green);
                                                //排序
                                                List<IGrouping<string, DIYLedModel>> dIYLedModelICGroup = rootDIYLedModel.DiyLedModelList.GroupBy(t => t.ICID).ToList();

                                                foreach (IGrouping<string, DIYLedModel> ICGroup in dIYLedModelICGroup)
                                                {
                                                    string IC = ICGroup.Key;

                                                    List<IGrouping<string, DIYLedModel>> dIYLedModelScanNumGroup = ICGroup.GroupBy(t => t.Scan_num).ToList();

                                                    foreach (IGrouping<string, DIYLedModel> ScanNumGroup in dIYLedModelScanNumGroup)
                                                    {
                                                        string ScanNum = ScanNumGroup.Key;

                                                        List<DIYLedModel> dIYLedModels = ScanNumGroup.OrderBy(a => a.LEDID).ToList();

                                                        int foregroundLight = 0;
                                                        int backgroundLight = 0;

                                                        int LedCount = ConfigInfo.TestConfig.IC_PinCount;

                                                        string LedData = "";

                                                        for (int indexLed = 1; indexLed < LedCount + 1; indexLed++)
                                                        {
                                                            DIYLedModel dIYLedModel = dIYLedModels.FirstOrDefault(s => s.LEDID == indexLed);

                                                            if (dIYLedModel == null)
                                                            {
                                                                LedData += " " + backgroundLight.ToString();
                                                            }
                                                            else
                                                            {
                                                                foregroundLight = dIYLedModel.LightValue;

                                                                if (dIYLedModel.IsFlag == Visibility.Visible)
                                                                {
                                                                    if (dIYLedModel.LedType == "Nomal")
                                                                    {
                                                                        LedData += " " + foregroundLight.ToString();
                                                                    }
                                                                    else
                                                                    {
                                                                        LedData += " " + foregroundLight.ToString();
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        DLEDLightingHelper.SetDIYPictureData(IC, ScanNum, LedData);
                                                    }

                                                }

                                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.showDIYPicture(0));

                                                if (!JudgeTestResult(testItemResult))
                                                {
                                                    isSuccess = false;

                                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                                    {
                                                        //this.ShowDialog("DIY 图案测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                                        this.ShowPromptWindow("DIY 图案测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                                        return;
                                                    }
                                                }

                                                Thread.Sleep(ConfigInfo.TestConfig.DIYPictureDelayTimeMs);
                                            }

                                        }
                                        //DLEDLightingHelper.DIYEnd();
                                    }
                                    else
                                    {
                                        foreach (RootDIYLedModel rootDIYLedModel in ConfigInfo.TestConfig.RootDiyLedModelList)
                                        {
                                            if (rootDIYLedModel.IsTest)
                                            {

                                                testItemResult.Result = "Testing";

                                                AppendTestData(string.Format("DIY 图案：{0}", rootDIYLedModel.RootName), MyBrushes.Green);
                                                //排序
                                                List<IGrouping<string, DIYLedModel>> dIYLedModelGroup = rootDIYLedModel.DiyLedModelList.GroupBy(t => t.ICID).ToList();

                                                foreach (IGrouping<string, DIYLedModel> group in dIYLedModelGroup)
                                                {

                                                    string IC = group.Key;

                                                    string Led = "";

                                                    int i = 0;

                                                    List<DIYLedModel> dIYLedModels = group.OrderBy(a => a.LEDID).ToList();

                                                    int foregroundLight = 0;
                                                    int backgroundLight = 0;

                                                    int LedCount = ConfigInfo.TestConfig.IC_PinCount;

                                                    //if (ConfigInfo.TestConfig.TestModelCode == 1 || ConfigInfo.TestConfig.TestModelCode == 8 || ConfigInfo.TestConfig.TestModelCode == 9 || ConfigInfo.TestConfig.TestModelCode == 11)
                                                    //{
                                                    //    LedCount = 16;

                                                    //}
                                                    //else if (ConfigInfo.TestConfig.TestModelCode == 10)
                                                    //{
                                                    //    LedCount = 38;
                                                    //}
                                                    //else
                                                    //{
                                                    //    LedCount = 48;
                                                    //}

                                                    for (int indexLed = 1; indexLed < LedCount + 1; indexLed++)
                                                    {
                                                        DIYLedModel dIYLedModel = dIYLedModels.FirstOrDefault(s => s.LEDID == indexLed);

                                                        if (dIYLedModel == null)
                                                        {
                                                            Led += " " + backgroundLight.ToString();
                                                        }
                                                        else
                                                        {
                                                            foregroundLight = dIYLedModel.LightValue;

                                                            if (dIYLedModel.IsFlag == Visibility.Visible)
                                                            {
                                                                if (dIYLedModel.LedType == "Nomal")
                                                                {
                                                                    Led += " " + foregroundLight.ToString();
                                                                }
                                                                else
                                                                {
                                                                    Led += " " + foregroundLight.ToString();//backgroundLight.ToString();
                                                                }
                                                            }
                                                        }
                                                    }


                                                    if (ConfigInfo.TestConfig.TestCaseType == 1 || ConfigInfo.TestConfig.TestCaseType == 3 || ConfigInfo.TestConfig.TestCaseType == 4 || ConfigInfo.TestConfig.TestCaseType == 5)
                                                    {

                                                        DLEDLightingHelper.SetDIYPictureData(IC, Led);
                                                    }
                                                    else
                                                    {
                                                        DLEDLightingHelper.SetCheckerBoardPictureData(IC, Led);
                                                    }
                                                }

                                                if (ConfigInfo.TestConfig.TestCaseType == 1 || ConfigInfo.TestConfig.TestCaseType == 3 || ConfigInfo.TestConfig.TestCaseType == 4 || ConfigInfo.TestConfig.TestCaseType == 5)
                                                {
                                                    testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.showDIYPicture(0));
                                                }
                                                else
                                                {

                                                    testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.ShowCheckerBoardPicture(ConfigInfo.TestConfig.DIYPictureSetValue));
                                                }

                                                if (!JudgeTestResult(testItemResult))
                                                {
                                                    isSuccess = false;
                                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                                    {
                                                        //this.ShowDialog("DIY 图案测试Fail,结束测试", "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                                        this.ShowPromptWindow("DIY 图案测试Fail,结束测试", PromptType.Red, 5, 0.2);
                                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                                        return;
                                                    }
                                                }
                                                //Thread.Sleep(3000);
                                                Thread.Sleep(ConfigInfo.TestConfig.DIYPictureDelayTimeMs);
                                            }

                                        }
                                    }
                                }
                                else
                                {
                                    testItemResult.ResultValue = "Success";
                                    testItemResult.Result = "Pass";
                                    AppendTestData(string.Format("{0}-{1} 成功", ">>>", testItemResult.Name), MyBrushes.Green);
                                }

                                //全电流测试结束增加关闭电源的功能 - AddByBandit - 2024年8月26日 17:20:16
                                if (( TestStation.ConfigInfo.TestConfig.TestModelCode == 17 || TestStation.ConfigInfo.TestConfig.TestModelCode == 31) && testItemResult.TestItemCode == "FullCurrentTest3")
                                {
                                    Thread.Sleep(100);
                                    DLEDLightingHelper.DIYEnd();

                                }
                            }
                            #endregion

                            int index = 0;

                            #region 全电流测试
                            if (testItemResult.TestItemCode == "FullCurrentTest1" || testItemResult.TestItemCode == "FullCurrentTest2" || testItemResult.TestItemCode == "FullCurrentTest3" || testItemResult.TestItemCode == "FullCurrentTest4" || testItemResult.TestItemCode == "FullCurrentTest5" || testItemResult.TestItemCode == "FullCurrentTest6")
                            {
                                index++;

                                this.SetMCDCBCScaleForTestItem(testItemResult);

                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetAllLEDTestData(testItemResult.SetCurrentValue));

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        //this.ShowDialog(string.Format("全电流测试{0}Fail,结束测试", index), "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                        //this.ShowPromptWindow(string.Format("全电流测试{0}Fail,结束测试", index), PromptType.Red, 5, 0.2);
                                        this.ShowPromptWindow(string.Format("{0}Fail,结束测试", testItemResult.Name), PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }

                                //全电流测试结束增加关闭电源的功能 - AddByBandit - 2024年8月26日 17:20:16
                                if ((TestStation.ConfigInfo.TestConfig.TestModelCode == 17|| TestStation.ConfigInfo.TestConfig.TestModelCode == 31) && testItemResult.TestItemCode == "FullCurrentTest3")
                                {
                                    Thread.Sleep(100);
                                    DLEDLightingHelper.DIYStart();
                                    
                                }
                            }
                            #endregion

                            #region ESD测试
                            if (testItemResult.TestItemCode == "ESDTest1")
                            {
                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetESDTestData((int)testItemResult.SetCurrentValue));

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        //this.ShowDialog(string.Format("全电流测试{0}Fail,结束测试", index), "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                        //this.ShowPromptWindow(string.Format("全电流测试{0}Fail,结束测试", index), PromptType.Red, 5, 0.2);
                                        this.ShowPromptWindow(string.Format("{0}Fail,结束测试", testItemResult.Name), PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }
                                if (testItemResult.DicResult != null)
                                {
                                    foreach (var item in testItemResult.DicResult)
                                    {
                                        if (item.Key == "CMD" || item.Key == "result")
                                        {
                                            continue;
                                        }
                                        else if (item.Key == "LEDVI")
                                        {
                                            string currentStr = item.Value.ToString().Split(",")[1].Replace("mA", "");

                                            double dCurrentValue = Convert.ToDouble(currentStr);

                                            if (dCurrentValue <= testItemResult.Limit.Upper && dCurrentValue >= testItemResult.Limit.Lower)
                                            {
                                                AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichGreen);
                                            }
                                            else
                                            {
                                                AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichRed);
                                            }
                                        }
                                        else
                                        {
                                            if (item.Value.ToString().Contains("1"))
                                            {
                                                AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichRed);
                                            }
                                            else
                                            {
                                                AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichGreen);
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region ESD测试
                            if (testItemResult.TestItemCode == "ESDTest2")
                            {
                                testItemResult.DicResult = JsonToDictionary(DLEDLightingHelper.GetESDTestData((int)testItemResult.SetCurrentValue));

                                if (!JudgeTestResult(testItemResult))
                                {
                                    isSuccess = false;
                                    if (App.SettingViewModel.Setting.IsFailEnd)
                                    {
                                        //this.ShowDialog(string.Format("全电流测试{0}Fail,结束测试", index), "异常提示", MessageBoxButton.OK, DialogIcon.Error);
                                        //this.ShowPromptWindow(string.Format("全电流测试{0}Fail,结束测试", index), PromptType.Red, 5, 0.2);
                                        this.ShowPromptWindow(string.Format("{0}Fail,结束测试", testItemResult.Name), PromptType.Red, 5, 0.2);
                                        AppendTestData(string.Format("{0}-{1} 异常,结束测试", testItemResult.Num, testItemResult.Name), MyBrushes.Red);
                                        return;
                                    }
                                }
                                if (testItemResult.DicResult != null)
                                {
                                    foreach (var item in testItemResult.DicResult)
                                    {
                                        if (item.Key == "CMD" || item.Key == "result")
                                        {
                                            continue;
                                        }
                                        else if (item.Key == "LEDVI")
                                        {
                                            string currentStr = item.Value.ToString().Split(",")[1].Replace("mA", "");

                                            double dCurrentValue = Convert.ToDouble(currentStr);

                                            if (dCurrentValue <= testItemResult.Limit.Upper && dCurrentValue >= testItemResult.Limit.Lower)
                                            {
                                                AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichGreen);
                                            }
                                            else
                                            {
                                                AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichRed);
                                            }
                                        }
                                        else
                                        {
                                            if (item.Value.ToString().Contains("1"))
                                            {
                                                AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichRed);
                                            }
                                            else
                                            {
                                                AppendTestData(string.Format("{0}:{1}", item.Key, item.Value), MyBrushes.RichGreen);
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion

                            //AppendTestData(string.Format("延时{0}ms", testItemResult.DelayTime), MyBrushes.Yellow);

                            //Thread.Sleep(testItemResult.DelayTime);

                        }
                    }

                }).ContinueWith(t =>
                {
                   
                    if (OnStartTestResultChanged != null)
                    {
                        OnStartTestResultChanged(this.TestStation, !TestStation.IsStop ? "Stop" : isSuccess.ToString());
                    }

                    FinishTest(!TestStation.IsStop, isSuccess);

                });

            }
            catch (Exception ex)
            {
                TestStation.IsStop = false;

                this.ShowPromptWindow("Throw Error:" + ex.Message, PromptType.Red);

                if (OnStartTestResultChanged != null)
                {
                    OnStartTestResultChanged(this.TestStation, !TestStation.IsStop ? "Stop" : "false");

                    if (TestStation.TestInfo.StationName.Contains("NTC"))
                    {
                        //NTC 测试完自动关灯
                        PowerOFFLed();
                    }
                }
            }
        }
        #endregion

        #region 设置MCDCBC

        private void SetMCDCBCScaleForTestItem(TestItemResult testItem)
        {
            if (ConfigInfo.TestConfig.TestCaseType == 1 || ConfigInfo.TestConfig.TestCaseType == 4 || ConfigInfo.TestConfig.TestCaseType == 5)
            {
                SetMC(testItem);
            }
            else if (ConfigInfo.TestConfig.TestCaseType == 3)
            {
                SetSCALE_ILED(testItem);
            }
            else
            {
                SetMCDCBC(testItem);

            }
        }

        private bool SetMCDCBC(TestItemResult testItemResult)
        {
            bool isSuccess = true;

            AppendTestData(string.Format("MC设置 : {0}", testItemResult.SetMcValue), MyBrushes.Yellow);

            if (!DLEDLightingHelper.SetMC(testItemResult.SetMcValue))
            {
                AppendTestData("MC设置失败", MyBrushes.Red);

                isSuccess = false;
            }
            else
            {

                AppendTestData("MC设置成功", MyBrushes.Green);
            }

            AppendTestData(string.Format("DC设置 : {0}", testItemResult.SetDcValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetDC(testItemResult.SetDcValue))
            {
                AppendTestData("DC设置失败", MyBrushes.Red);
                isSuccess = false;
            }
            else
            {

                AppendTestData("DC设置成功", MyBrushes.Green);
            }

            AppendTestData(string.Format("BC设置 : {0}", testItemResult.SetBcValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetBC(testItemResult.SetBcValue))
            {
                AppendTestData("BC设置失败", MyBrushes.Red);
                isSuccess = false;
            }
            else
            {

                AppendTestData("BC设置成功", MyBrushes.Green);
            }

            return isSuccess;
        }

        private bool SetSCALE_ILED(TestItemResult testItemResult)
        {
            bool isSuccess = true;

            AppendTestData(string.Format("Scale设置 : {0}", testItemResult.SetScaleValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetSCALE(testItemResult.SetScaleValue))
            {
                AppendTestData("Scale设置失败", MyBrushes.Red);

                isSuccess = false;
            }
            else
            {

                AppendTestData("Scale设置成功", MyBrushes.Green);
            }

            AppendTestData(string.Format("ILED设置 : {0}", testItemResult.SetILedValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetILED(testItemResult.SetILedValue))
            {
                AppendTestData("ILED设置失败", MyBrushes.Red);
                isSuccess = false;
            }
            else
            {

                AppendTestData("ILED设置成功", MyBrushes.Green);
            }
            return isSuccess;
        }
        private bool SetMC(TestItemResult testItemResult)
        {
            bool isSuccess = true;

            AppendTestData(string.Format("MC设置 : {0}", testItemResult.SetMcValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetMC(testItemResult.SetMcValue))
            {
                AppendTestData("MC设置失败", MyBrushes.Red);

                isSuccess = false;
            }
            else
            {

                AppendTestData("MC设置成功", MyBrushes.Green);
            }

            return isSuccess;
        }

        private void SetMCDCBCScale()
        {
            if (ConfigInfo.TestConfig.TestCaseType == 1 || ConfigInfo.TestConfig.TestCaseType == 4 || ConfigInfo.TestConfig.TestCaseType == 5)
            {
                SetMC(ConfigInfo.TestConfig.IMCValue);

            }
            else if (ConfigInfo.TestConfig.TestCaseType == 3)
            {
                SetSCALE_ILED(ConfigInfo.TestConfig.IScaleValue, ConfigInfo.TestConfig.IILEDValue);
            }
            else
            {
                SetMCDCBC(ConfigInfo.TestConfig.IMCValue, ConfigInfo.TestConfig.IDCValue, ConfigInfo.TestConfig.IBCValue);
            }

        }

        private void SetMCDCBCScaleForDIY()
        {
            if (ConfigInfo.TestConfig.TestCaseType == 1 || ConfigInfo.TestConfig.TestCaseType == 4 || ConfigInfo.TestConfig.TestCaseType == 5)
            {
                SetMC(ConfigInfo.TestConfig.DIYPictureSetMC);
            }
            else if (ConfigInfo.TestConfig.TestCaseType == 3)
            {
                SetSCALE_ILED(ConfigInfo.TestConfig.DIYPictureSetScale, ConfigInfo.TestConfig.DIYPictureSetILED);
            }
            else
            {
                SetMCBC(ConfigInfo.TestConfig.DIYPictureSetMC, ConfigInfo.TestConfig.DIYPictureSetBC);

            }

        }
        private bool SetMCDCBC(int MCValue, int DCValue, int BCValue)
        {
            bool isSuccess = true;

            AppendTestData(string.Format("MC设置 : {0}", MCValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetMC(MCValue))
            {
                AppendTestData("MC设置失败", MyBrushes.Red);

                isSuccess = false;
            }
            else
            {

                AppendTestData("MC设置成功", MyBrushes.Green);
            }

            AppendTestData(string.Format("DC设置 : {0}", DCValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetDC(DCValue))
            {
                AppendTestData("DC设置失败", MyBrushes.Red);
                isSuccess = false;
            }
            else
            {

                AppendTestData("DC设置成功", MyBrushes.Green);
            }

            AppendTestData(string.Format("BC设置 : {0}", BCValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetBC(BCValue))
            {
                AppendTestData("BC设置失败", MyBrushes.Red);
                isSuccess = false;
            }
            else
            {

                AppendTestData("BC设置成功", MyBrushes.Green);
            }

            return isSuccess;
        }

        private bool SetSCALE_ILED(int ScaleValue, int ILEDValue)
        {
            bool isSuccess = true;

            AppendTestData(string.Format("Scale设置 : {0}", ScaleValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetSCALE(ScaleValue))
            {
                AppendTestData("Scale设置失败", MyBrushes.Red);

                isSuccess = false;
            }
            else
            {

                AppendTestData("Scale设置成功", MyBrushes.Green);
            }

            AppendTestData(string.Format("ILED设置 : {0}", ILEDValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetILED(ILEDValue))
            {
                AppendTestData("ILED设置失败", MyBrushes.Red);
                isSuccess = false;
            }
            else
            {

                AppendTestData("ILED设置成功", MyBrushes.Green);
            }
            return isSuccess;
        }
        private bool SetMCBC(int MCValue, int BCValue)
        {
            bool isSuccess = true;

            AppendTestData(string.Format("MC设置 : {0}", MCValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetMC(MCValue))
            {
                AppendTestData("MC设置失败", MyBrushes.Red);

                isSuccess = false;
            }
            else
            {

                AppendTestData("MC设置成功", MyBrushes.Green);
            }

            AppendTestData(string.Format("BC设置 : {0}", BCValue), MyBrushes.Yellow);
            if (!DLEDLightingHelper.SetBC(BCValue))
            {
                AppendTestData("BC设置失败", MyBrushes.Red);
                isSuccess = false;
            }
            else
            {

                AppendTestData("BC设置成功", MyBrushes.Green);
            }

            return isSuccess;
        }

        private bool SetMC(int MCValue)
        {
            bool isSuccess = true;

            AppendTestData(string.Format("MC设置 : {0}", MCValue), MyBrushes.Yellow);

            if (!DLEDLightingHelper.SetMC(MCValue))
            {
                AppendTestData("MC设置失败", MyBrushes.Red);

                isSuccess = false;
            }
            else
            {

                AppendTestData("MC设置成功", MyBrushes.Green);
            }

            return isSuccess;
        }
        #endregion

        #region 判断测试项

        private double vledCloseCurrent = 0;
        private bool JudgeTestResult(TestItemResult testItemResult)
        {
            if (testItemResult.DicResult == null || testItemResult.DicResult["result"].ToString() != "success")
            {
                testItemResult.ResultValue = "Fail";
                testItemResult.Result = "Fail";
                AppendTestData(string.Format("{0}-{1} 异常,指令返回Fail或测试结果为空", ">>>", testItemResult.Name), MyBrushes.Red);
                return false;
            }
            else
            {
                if (testItemResult.TestItemCode == "PINShortOpenTest" || testItemResult.TestItemCode == "DIYPattenDisplay" || testItemResult.TestItemCode == "QiPanPattenDisplay")
                {
                    testItemResult.ResultValue = "Success";
                    testItemResult.Result = "Pass";
                    AppendTestData(string.Format("{0}-{1} 成功", ">>>", testItemResult.Name), MyBrushes.Green);
                    return true;
                }

                string strValue = "";

                #region NTC极性
                if (testItemResult.TestItemCode == "DiodePolarityTest")
                {

                    strValue = testItemResult.DicResult["ntc1_Diode_Polarity_Vol"].ToString();

                    if (strValue.ToUpper() == "OL")
                    {
                        testItemResult.ResultValue = strValue;
                        testItemResult.Result = "Pass";
                        AppendTestData(string.Format("{0}-{1} 成功", ">>>", testItemResult.Name), MyBrushes.Green);
                        return true;
                    }
                    else
                    {
                        testItemResult.ResultValue = strValue;
                        testItemResult.Result = "Fail";
                        AppendTestData(string.Format("{0}-{1} 失败", ">>>", testItemResult.Name), MyBrushes.Red);
                        return false;
                    }

                }

                #endregion

                #region ESD测试
                if (testItemResult.TestItemCode.Contains("ESDTest"))
                {
                    List<string> keyStr = new List<string>();

                    foreach (var key in testItemResult.DicResult.Keys)
                    {
                        if (key.StartsWith("EVEN_BIST"))
                        {
                            keyStr.Add(key);
                        }

                    }
                    bool isBISTOK = true;

                    foreach (string key in keyStr)
                    {
                        string Str = testItemResult.DicResult[key].ToString();

                        string[] EVEN_BISTStrArr = Str.Split(',');

                        EVEN_BISTStrArr = EVEN_BISTStrArr.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                        for (int i = 0; i < EVEN_BISTStrArr.Length; i++)
                        {
                            int iStr = Convert.ToInt32((string)EVEN_BISTStrArr[i].Trim(), 16);

                            string binStr = Convert.ToString(iStr, 2).PadLeft(8, '0');

                            if (binStr.Contains("1"))
                            {
                                isBISTOK = false;
                            }
                        }
                    }

                    strValue = testItemResult.DicResult["LEDVI"].ToString().Split(',')[1].Replace("mA", "");

                    double dCValue = Convert.ToDouble(strValue);

                    if (testItemResult.IsSetCompensationValue && testItemResult.SetCompensationValue!=0)
                    {
                        AppendTestData($"{testItemResult.Name} 测试值 {dCValue} 补偿值{testItemResult.SetCompensationValue}", MyBrushes.Yellow);

                        dCValue += testItemResult.SetCompensationValue;
                    }

                    if (dCValue <= testItemResult.Limit.Upper && dCValue >= testItemResult.Limit.Lower && isBISTOK)
                    {
                        testItemResult.ResultValue = Math.Round(dCValue, 3).ToString();
                        testItemResult.Result = "Pass";
                        AppendTestData(string.Format("{0}-{1} 成功，值为：{2},Limit-Lower:{3},Upper:{4},EVEN_BIST结果：{5}", ">>>", testItemResult.Name, dCValue, testItemResult.Limit.Lower, testItemResult.Limit.Upper, isBISTOK.ToString()), MyBrushes.Green);
                        return true;
                    }
                    else
                    {
                        testItemResult.ResultValue = Math.Round(dCValue, 3).ToString();
                        testItemResult.Result = "Fail";
                        AppendTestData(string.Format("{0}-{1} 失败，值为：{2},Limit-Lower:{3},Upper:{4},EVEN_BIST结果：{5}", ">>>", testItemResult.Name, dCValue, testItemResult.Limit.Lower, testItemResult.Limit.Upper, isBISTOK.ToString()), MyBrushes.Red);
                        return false;
                    }
                }
                #endregion

                #region NTC热敏电阻测试
                if (testItemResult.TestItemCode == "ThermistorTestingRoomTemperature" || testItemResult.TestItemCode == "ThermistorTestingLightingTemperature")
                {
                    List<string> keyStr = new List<string>();

                    foreach (var key in testItemResult.DicResult.Keys)
                    {
                        if (key.StartsWith("NTC"))
                        {
                            keyStr.Add(key);
                        }
                    }

                    bool isNtcOk = true;
                    string NtcValue = "";
                    foreach (var key in keyStr)
                    {
                        strValue = testItemResult.DicResult[key].ToString();

                        double dNtcValue = Convert.ToDouble(strValue);

                        if (testItemResult.IsSetCompensationValue && testItemResult.SetCompensationValue != 0)
                        {
                            AppendTestData($"{testItemResult.Name} 测试值 {dNtcValue} 补偿值{testItemResult.SetCompensationValue}", MyBrushes.Yellow);

                            dNtcValue += testItemResult.SetCompensationValue;
                        }

                        NtcValue += Math.Round(dNtcValue, 3).ToString() + ";";

                        if (dNtcValue <= testItemResult.Limit.Upper && dNtcValue >= testItemResult.Limit.Lower)
                        {


                        }
                        else
                        {
                            isNtcOk = false;
                        }
                    }
                    //截取掉最后一个逗号
                    testItemResult.ResultValue = NtcValue.Substring(0, NtcValue.Length - 1);

                    if (isNtcOk)
                    {
                        testItemResult.Result = "Pass";
                        AppendTestData(string.Format("{0}-{1} 成功,值为：{2}，Limit-Lower:{3}，Upper：{4}", ">>>", testItemResult.Name, testItemResult.ResultValue, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Green);
                        return true;
                    }
                    else
                    {
                        testItemResult.Result = "Fail";
                        AppendTestData(string.Format("{0}-{1} 失败,值为：{2}，Limit-Lower:{3}，Upper：{4}", ">>>", testItemResult.Name, testItemResult.ResultValue, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Red);
                        return false;
                    }

                }
                #endregion

                #region IFBDataTest
                if (testItemResult.TestItemCode == "IFBDataTest")
                {
                    strValue = testItemResult.DicResult["IFB"].ToString().Replace("uA", "");

                }
                #endregion

                #region 芯片待机、正常电流
                if (testItemResult.TestItemCode == "ChipStandbyCurrent" || testItemResult.TestItemCode == "ChipWorkingCurrent")
                {
                    strValue = testItemResult.DicResult["LED_DriverIC_Current       mA"].ToString();
                }
                #endregion

                #region 全电流点灯

                if (testItemResult.TestItemCode == "VLEDFullyClosedCurrent" || testItemResult.TestItemCode == "FullScreenLowCurrent" || testItemResult.TestItemCode == "FullScreenHighCurrent" || testItemResult.TestItemCode == "FullCurrentTest1" || testItemResult.TestItemCode == "FullCurrentTest2" || testItemResult.TestItemCode == "FullCurrentTest3" || testItemResult.TestItemCode == "FullCurrentTest4" || testItemResult.TestItemCode == "FullCurrentTest5" || testItemResult.TestItemCode == "FullCurrentTest6")
                {
                    strValue = testItemResult.DicResult["LEDVI"].ToString();

                    string[] ledVi = strValue.Split(",");

                    if (ledVi.Count() > 1)
                    {
                        strValue = ledVi[1].Replace("mA", "");
                    }
                    else
                    {
                        strValue = "0";
                    }

                }

                #endregion

                #region 单路LED 高低电流点灯

                if (testItemResult.TestItemCode == "SingleLEDLowCurrent" || testItemResult.TestItemCode == "SingleLEDHighCurrent")
                {
                    List<string> keyStr = new List<string>();

                    foreach (var key in testItemResult.DicResult.Keys)
                    {
                        if (key.StartsWith("LEDVI"))
                        {
                            keyStr.Add(key);
                        }
                    }

                    bool IsOk = true;

                    foreach (string key in keyStr)
                    {
                        string ICNum = key.Split('-')[1].Replace("IC", "");
                        string LEDNum = key.Split("-")[2].Replace("CH", "");
                        string Name = "LED_" + int.Parse(ICNum).ToString() + "_" + (int.Parse(LEDNum) + 1).ToString().Replace(" ", "");

                        DIYLedModel dIYLedModel = TestStation.LedModelList.Find(x => x.Name == Name);

                        if (dIYLedModel == null)
                        {
                            //testItemResult.ResultValue = "Fail";
                            //testItemResult.Result = "Fail";
                            //AppendTestData(string.Format("{0}-{1} 失败,值为：null", ">>>", testItemResult.Name), MyBrushes.Red);
                            //return false;
                            continue;
                        }

                        dIYLedModel.Remark = Name + ":" + testItemResult.DicResult[key].ToString();

                        string currentStr = testItemResult.DicResult[key].ToString().Split(",")[1].Replace("mA", "");

                        double dCurrentValue = Convert.ToDouble(currentStr);

                        if (dCurrentValue <= testItemResult.Limit.Upper && dCurrentValue >= testItemResult.Limit.Lower)
                        {

                        }
                        else
                        {
                            dIYLedModel.LedType = "OpenShort";

                            IsOk = false;

                        }

                    }

                    if (IsOk)
                    {
                        testItemResult.ResultValue = "Success";
                        testItemResult.Result = "Pass";
                        AppendTestData(string.Format("{0}-{1} 成功，Limit-Lower:{2}，Upper：{3}", ">>>", testItemResult.Name, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Green);
                        return true;

                    }
                    else
                    {
                        testItemResult.ResultValue = "Fail";
                        testItemResult.Result = "Fail";
                        AppendTestData(string.Format("{0}-{1} 失败,Limit-Lower:{2}，Upper：{3}", ">>>", testItemResult.Name, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Red);
                        return false;
                    }
                }

                #endregion

                #region LED单芯片回路高低电流点灯

                if (testItemResult.TestItemCode == "LEDSingleICLowCurrent" || testItemResult.TestItemCode == "LEDSingleICHighCurrent")
                {
                    List<string> keyStr = new List<string>();

                    foreach (var key in testItemResult.DicResult.Keys)
                    {
                        if (key.StartsWith("LEDVI"))
                        {
                            keyStr.Add(key);
                        }
                    }

                    Dictionary<string, object> dic = new Dictionary<string, object>();

                    bool isOk = true;

                    foreach (string key in keyStr)
                    {
                        string currentStr = testItemResult.DicResult[key].ToString().Split(",")[1].Replace("mA", "");

                        double dCurrentValue = Convert.ToDouble(currentStr);

                        if (testItemResult.IsSetCompensationValue && testItemResult.SetCompensationValue != 0)
                        {

                            AppendTestData($"{testItemResult.Name} 测试值 {dCurrentValue} 补偿值{testItemResult.SetCompensationValue}", MyBrushes.Yellow);

                            dCurrentValue += testItemResult.SetCompensationValue;
                        }

                        if (ConfigInfo.TestConfig.TestModelCode == 11)
                        {
                            dCurrentValue = dCurrentValue - vledCloseCurrent;
                            AppendTestData(string.Format("SD058A {0}电流减去漏电流:", key) + vledCloseCurrent.ToString(), MyBrushes.Yellow);
                        }

                        dic.Add(key, dCurrentValue);

                        if (dCurrentValue <= testItemResult.Limit.Upper && dCurrentValue >= testItemResult.Limit.Lower)
                        {

                        }
                        else
                        {
                            isOk = false;
                        }

                    }

                    testItemResult.DicResult = dic;

                    if (isOk)
                    {
                        testItemResult.ResultValue = "Success";
                        testItemResult.Result = "Pass";
                        AppendTestData(string.Format("{0}-{1} 成功,Limit-Lower:{2}，Upper：{3}", ">>>", testItemResult.Name, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Green);
                        return true;
                    }
                    else
                    {
                        testItemResult.ResultValue = "Fail";
                        testItemResult.Result = "Fail";
                        AppendTestData(string.Format("{0}-{1} 失败,Limit-Lower:{2}，Upper：{3}", ">>>", testItemResult.Name, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Red);
                        return false;
                    }

                }

                #endregion

                #region 10uA电流测试 openshort测试
                if (testItemResult.TestItemCode == "CurrentTest10uA")
                {

                    if (ConfigInfo.TestConfig.TestModelCode == 11 || ConfigInfo.TestConfig.TestModelCode == 17 || ConfigInfo.TestConfig.TestModelCode == 31)
                    {

                        List<string> OpenkeyStr = new List<string>();
                        List<string> ShortkeyStr = new List<string>();

                        foreach (var Openkey in testItemResult.DicResult.Keys)
                        {
                            if (Openkey.StartsWith("OpenStatus"))
                            {
                                OpenkeyStr.Add(Openkey);
                            }
                        }

                        foreach (var Shortkey in testItemResult.DicResult.Keys)
                        {
                            if (Shortkey.StartsWith("ShortStatus"))
                            {
                                ShortkeyStr.Add(Shortkey);
                            }
                        }
                        bool iSOpenShort = true;

                        if (OpenkeyStr.Count() > 0 || ShortkeyStr.Count() > 0)
                        {
                            foreach (string key in OpenkeyStr)
                            {
                                string[] OpenKeyArr = key.Split('-');

                                int iScanNum = int.Parse(OpenKeyArr[1].Replace("Scan", "")) - 1;

                                int iICID = int.Parse(OpenKeyArr[2].Replace("IC", "")) - 1;

                                string Str = testItemResult.DicResult[key].ToString();

                                string[] OpenStrArr = Str.Split(',');

                                OpenStrArr = OpenStrArr.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                                for (int i = 0; i < OpenStrArr.Length; i++)
                                {
                                    int iStr = Convert.ToInt32((string)OpenStrArr[i].Trim(), 16);

                                    string binStr = Convert.ToString(iStr, 2).PadLeft(8, '0');

                                    int a = 0;
                                    int iCount = OpenStrArr.Length - i;

                                    //string binStrt = "";
                                    //for(int id = binStr.Length-1;id>=0;id--)
                                    //{
                                    //    binStrt += binStr[id];
                                    //}

                                    foreach (char c in binStr)
                                    {
                                        int iLed = iCount * 8 - a;

                                        DIYLedModel dIYLedModel = TestStation.LedModelList.Find(x => x.Scan_num == iScanNum.ToString() && x.ICID == iICID.ToString() && x.LEDID == iLed);

                                        if (dIYLedModel != null)
                                        {

                                            if (c == '0')
                                            {
                                                if (dIYLedModel.LedType != "Short")
                                                {
                                                    dIYLedModel.LedType = "Nomal";
                                                }
                                            }
                                            else
                                            {
                                                if (dIYLedModel.LedType == "Short" || dIYLedModel.LedType == "OpenShort")
                                                {
                                                    dIYLedModel.LedType = "OpenShort";
                                                }
                                                else
                                                {
                                                    dIYLedModel.LedType = "Open";
                                                }
                                                iSOpenShort = false;
                                            }

                                        }

                                        a++;
                                    }


                                }

                            }

                            foreach (string key in ShortkeyStr)
                            {
                                string[] ShortKeyArr = key.Split('-');

                                int iScanNum = int.Parse(ShortKeyArr[1].Replace("Scan", "")) - 1;

                                int iICID = int.Parse(ShortKeyArr[2].Replace("IC", "")) - 1;

                                string Str = testItemResult.DicResult[key].ToString();

                                string[] ShortStrArr = Str.Split(',');

                                ShortStrArr = ShortStrArr.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                                for (int i = 0; i < ShortStrArr.Length; i++)
                                {
                                    int iStr = Convert.ToInt32((string)ShortStrArr[i].Trim(), 16);

                                    string binStr = Convert.ToString(iStr, 2).PadLeft(8, '0');

                                    int a = 0;
                                    int iCount = ShortStrArr.Length - i - 1;

                                    foreach (char c in binStr)
                                    {
                                        int iLed = iCount * 8 + 8 - a;

                                        DIYLedModel dIYLedModel = TestStation.LedModelList.Find(x => x.Scan_num == iScanNum.ToString() && x.ICID == iICID.ToString() && x.LEDID == iLed);

                                        if (dIYLedModel != null)
                                        {

                                            if (c == '0')
                                            {
                                                if (dIYLedModel.LedType != "Open")
                                                {
                                                    dIYLedModel.LedType = "Nomal";
                                                }
                                            }
                                            else
                                            {
                                                if (dIYLedModel.LedType == "Open" || dIYLedModel.LedType == "OpenShort")
                                                {
                                                    dIYLedModel.LedType = "OpenShort";
                                                }
                                                else
                                                {
                                                    dIYLedModel.LedType = "Short";
                                                }
                                                iSOpenShort = false;
                                            }

                                        }

                                        a++;
                                    }

                                }

                            }
                        }
                        else
                        {
                            iSOpenShort = false;
                        }

                        if (iSOpenShort)
                        {
                            testItemResult.ResultValue = "Success";
                            testItemResult.Result = "Pass";
                            AppendTestData(string.Format("{0}-{1} 成功", ">>>", testItemResult.Name), MyBrushes.Green);
                            return true;
                        }
                        else
                        {
                            testItemResult.ResultValue = "Fail";
                            testItemResult.Result = "Fail";
                            AppendTestData(string.Format("{0}-{1} 失败", ">>>", testItemResult.Name), MyBrushes.Red);
                            return false;
                        }
                    }
                    else
                    {
                        List<string> OpenkeyStr = new List<string>();
                        List<string> ShortkeyStr = new List<string>();

                        foreach (var Openkey in testItemResult.DicResult.Keys)
                        {
                            if (Openkey.StartsWith("OpenStatus"))
                            {
                                OpenkeyStr.Add(Openkey);
                            }
                        }

                        foreach (var Shortkey in testItemResult.DicResult.Keys)
                        {
                            if (Shortkey.StartsWith("ShortStatus"))
                            {
                                ShortkeyStr.Add(Shortkey);
                            }
                        }

                        bool iSOpenShort = true;

                        if (OpenkeyStr.Count() > 0 || ShortkeyStr.Count() > 0)
                        {
                            foreach (string key in OpenkeyStr)
                            {
                                string[] OpenKeyArr = key.Split('-');

                                int iICID = int.Parse(OpenKeyArr[1].Replace("IC", ""));

                                string Str = testItemResult.DicResult[key].ToString();

                                string[] OpenStrArr = Str.Split(',');

                                OpenStrArr = OpenStrArr.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                                for (int i = 0; i < OpenStrArr.Length; i++)
                                {
                                    int iStr = Convert.ToInt32((string)OpenStrArr[i].Trim(), 16);

                                    string binStr = Convert.ToString(iStr, 2).PadLeft(8, '0');

                                    int a = 0;
                                    int iCount = OpenStrArr.Length - i;

                                    //string binStrt = "";
                                    //for(int id = binStr.Length-1;id>=0;id--)
                                    //{
                                    //    binStrt += binStr[id];
                                    //}

                                    foreach (char c in binStr)
                                    {
                                        int iLed = iCount * 8 - a;

                                        DIYLedModel dIYLedModel = TestStation.LedModelList.Find(x => x.ICID == iICID.ToString() && x.LEDID == iLed);

                                        if (dIYLedModel != null)
                                        {

                                            if (c == '0')
                                            {
                                                if (dIYLedModel.LedType != "Short")
                                                {
                                                    dIYLedModel.LedType = "Nomal";
                                                }
                                            }
                                            else
                                            {
                                                if (dIYLedModel.LedType == "Short" || dIYLedModel.LedType == "OpenShort")
                                                {
                                                    dIYLedModel.LedType = "OpenShort";
                                                }
                                                else
                                                {
                                                    dIYLedModel.LedType = "Open";
                                                }
                                                iSOpenShort = false;
                                            }

                                        }

                                        a++;
                                    }


                                }

                            }

                            foreach (string key in ShortkeyStr)
                            {
                                string[] ShortKeyArr = key.Split('-');

                                int iICID = int.Parse(ShortKeyArr[1].Replace("IC", ""));

                                string Str = testItemResult.DicResult[key].ToString();

                                string[] ShortStrArr = Str.Split(',');

                                ShortStrArr = ShortStrArr.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                                for (int i = 0; i < ShortStrArr.Length; i++)
                                {
                                    int iStr = Convert.ToInt32((string)ShortStrArr[i].Trim(), 16);

                                    string binStr = Convert.ToString(iStr, 2).PadLeft(8, '0');

                                    int a = 0;
                                    int iCount = ShortStrArr.Length - i - 1;

                                    foreach (char c in binStr)
                                    {
                                        int iLed = iCount * 8 + 8 - a;

                                        DIYLedModel dIYLedModel = TestStation.LedModelList.Find(x => x.ICID == iICID.ToString() && x.LEDID == iLed);

                                        if (dIYLedModel != null)
                                        {

                                            if (c == '0')
                                            {
                                                if (dIYLedModel.LedType != "Open")
                                                {
                                                    dIYLedModel.LedType = "Nomal";
                                                }
                                            }
                                            else
                                            {
                                                if (dIYLedModel.LedType == "Open" || dIYLedModel.LedType == "OpenShort")
                                                {
                                                    dIYLedModel.LedType = "OpenShort";
                                                }
                                                else
                                                {
                                                    dIYLedModel.LedType = "Short";
                                                }
                                                iSOpenShort = false;
                                            }

                                        }

                                        a++;
                                    }

                                }

                            }
                        }
                        else
                        {
                            iSOpenShort = false;
                        }
                        if (iSOpenShort)
                        {
                            testItemResult.ResultValue = "Success";
                            testItemResult.Result = "Pass";
                            AppendTestData(string.Format("{0}-{1} 成功", ">>>", testItemResult.Name), MyBrushes.Green);
                            return true;
                        }
                        else
                        {
                            testItemResult.ResultValue = "Fail";
                            testItemResult.Result = "Fail";
                            AppendTestData(string.Format("{0}-{1} 失败", ">>>", testItemResult.Name), MyBrushes.Red);
                            return false;
                        }
                    }
                }
                #endregion

                double dValue = Convert.ToDouble(strValue);

                if (testItemResult.IsSetCompensationValue && testItemResult.SetCompensationValue != 0)
                {
                    AppendTestData($"{testItemResult.Name} 测试值 {dValue} 补偿值{testItemResult.SetCompensationValue}", MyBrushes.Yellow);
                    dValue += testItemResult.SetCompensationValue;
                }

                Dictionary<string, object> Resultdic = new Dictionary<string, object>();
                string Remark = "";

                //EditByBandit 2024年5月3日 13:47:46
                if (testItemResult.TestItemCode == "VLEDFullyClosedCurrent")
                {
                    vledCloseCurrent = dValue;

                    dValue = dValue + ConfigInfo.TestConfig.VLEDFullyClosedCurrentOffset;//ConfigHelper.GetValueToDouble("VLEDFullyClosedCurrentOffset", 0);

                    Resultdic.Add("LEDVI", dValue);

                    testItemResult.DicResult = Resultdic;
                }

                if ((testItemResult.TestItemCode == "FullScreenLowCurrent" || testItemResult.TestItemCode == "FullScreenHighCurrent" || testItemResult.TestItemCode == "FullCurrentTest1" || testItemResult.TestItemCode == "FullCurrentTest2" || testItemResult.TestItemCode == "FullCurrentTest3" || testItemResult.TestItemCode == "FullCurrentTest4" || testItemResult.TestItemCode == "FullCurrentTest5" || testItemResult.TestItemCode == "FullCurrentTest6") && TestStation.TestInfo.StationName.Contains("NTC"))
                {

                    bool isOpenShortFull = false;

                    if (ConfigInfo.TestConfig.TestModelCode == 11 && ConfigHelper.GetValueToInt("IsReduceCloseCurrent", 0) == 1)
                    {
                        dValue = dValue - vledCloseCurrent;//ConfigInfo.TestConfig.VLEDFullyClosedCurrentOffset;
                        AppendTestData("SD058A " + testItemResult.Name + "减去漏电流:" + vledCloseCurrent.ToString(), MyBrushes.Yellow);
                    }

                    Resultdic.Add("LEDVI", dValue);

                    if (ConfigInfo.TestConfig.TestModelCode != 12 && ConfigInfo.TestConfig.TestModelCode != 14 && ConfigInfo.TestConfig.TestModelCode != 15)
                    {
                        if (ConfigInfo.TestConfig.TestModelCode == 11 || ConfigInfo.TestConfig.TestModelCode == 17 || ConfigInfo.TestConfig.TestModelCode == 31)
                        {
                            //foreach (var re in testItemResult.DicResult)
                            //{
                            //    if (re.Value.ToString().Replace("0", "").Replace("x", "") != "")
                            //    {
                            //        testItemResult.ResultValue = "Fail";
                            //        testItemResult.Result = "Fail";
                            //        AppendTestData(string.Format("{0}-{1} 失败", ">>>", testItemResult.Name), MyBrushes.Red);
                            //        return false;
                            //    }
                            //}
                            //testItemResult.ResultValue = "Success";
                            //testItemResult.Result = "Pass";
                            //AppendTestData(string.Format("{0}-{1} 成功", ">>>", testItemResult.Name), MyBrushes.Green);
                            //return true;
                            List<string> OpenkeyStr = new List<string>();
                            List<string> ShortkeyStr = new List<string>();

                            foreach (var Openkey in testItemResult.DicResult.Keys)
                            {
                                if (Openkey.StartsWith("OpenStatus"))
                                {
                                    OpenkeyStr.Add(Openkey);
                                }
                            }

                            foreach (var Shortkey in testItemResult.DicResult.Keys)
                            {
                                if (Shortkey.StartsWith("ShortStatus"))
                                {
                                    ShortkeyStr.Add(Shortkey);
                                }
                            }

                            if (OpenkeyStr.Count() > 0 || ShortkeyStr.Count() > 0)
                            {
                                string openPositionStr = "";

                                foreach (string key in OpenkeyStr)
                                {

                                    bool IsOpen = false;

                                    string[] OpenKeyArr = key.Split('-');

                                    int iScanNum = int.Parse(OpenKeyArr[1].Replace("Scan", "")) - 1;

                                    int iICID = int.Parse(OpenKeyArr[2].Replace("IC", "")) - 1;

                                    string Str = testItemResult.DicResult[key].ToString();

                                    string[] OpenStrArr = Str.Split(',');

                                    OpenStrArr = OpenStrArr.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                                    for (int i = 0; i < OpenStrArr.Length; i++)
                                    {
                                        int iStr = Convert.ToInt32((string)OpenStrArr[i].Trim(), 16);

                                        string binStr = Convert.ToString(iStr, 2).PadLeft(8, '0');

                                        int a = 0;

                                        int iCount = OpenStrArr.Length - i;

                                        foreach (char c in binStr)
                                        {
                                            int iLed = iCount * 8 - a;

                                            DIYLedModel dIYLedModel = TestStation.LedModelList.Find(x => x.Scan_num == iScanNum.ToString() && x.ICID == iICID.ToString() && x.LEDID == iLed);

                                            if (dIYLedModel != null)
                                            {

                                                if (c == '0')
                                                {

                                                }
                                                else
                                                {
                                                    openPositionStr += "【" + (iScanNum + 1).ToString() + "_" + (iICID + 1).ToString() + "_" + iLed.ToString() + "】" + ";";

                                                    IsOpen = true;
                                                }

                                            }

                                            a++;
                                        }


                                    }

                                    if (IsOpen)
                                    {
                                        isOpenShortFull = true;
                                        Resultdic.Add(key, testItemResult.DicResult[key].ToString());
                                    }
                                }

                                Remark += "Open:" + openPositionStr + "\r\n";

                                string shortPositionStr = "";

                                foreach (string key in ShortkeyStr)
                                {
                                    bool isShort = false;

                                    string[] ShortKeyArr = key.Split('-');

                                    int iScanNum = int.Parse(ShortKeyArr[1].Replace("Scan", "")) - 1;

                                    int iICID = int.Parse(ShortKeyArr[2].Replace("IC", "")) - 1;

                                    string Str = testItemResult.DicResult[key].ToString();

                                    string[] ShortStrArr = Str.Split(',');

                                    ShortStrArr = ShortStrArr.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                                    for (int i = 0; i < ShortStrArr.Length; i++)
                                    {
                                        int iStr = Convert.ToInt32((string)ShortStrArr[i].Trim(), 16);

                                        string binStr = Convert.ToString(iStr, 2).PadLeft(8, '0');

                                        int a = 0;
                                        int iCount = ShortStrArr.Length - i - 1;

                                        foreach (char c in binStr)
                                        {
                                            int iLed = iCount * 8 + 8 - a;

                                            DIYLedModel dIYLedModel = TestStation.LedModelList.Find(x => x.Scan_num == iScanNum.ToString() && x.ICID == iICID.ToString() && x.LEDID == iLed);

                                            if (dIYLedModel != null)
                                            {

                                                if (c == '0')
                                                {

                                                }
                                                else
                                                {
                                                    shortPositionStr += "【" + (iScanNum + 1).ToString() + "_" + (iICID + 1).ToString() + "_" + iLed.ToString() + "】" + ";";

                                                    isShort = true;
                                                }

                                            }

                                            a++;
                                        }

                                    }

                                    if (isShort)
                                    {

                                        isOpenShortFull = true;
                                        Resultdic.Add(key, testItemResult.DicResult[key].ToString());
                                    }
                                }

                                Remark += "Short:" + shortPositionStr + "\r\n";

                            }
                        }
                        
                        else
                        {
                            List<string> OpenkeyStr = new List<string>();
                            List<string> ShortkeyStr = new List<string>();

                            foreach (var Openkey in testItemResult.DicResult.Keys)
                            {
                                if (Openkey.StartsWith("OpenStatus"))
                                {
                                    OpenkeyStr.Add(Openkey);
                                }
                            }

                            foreach (var Shortkey in testItemResult.DicResult.Keys)
                            {
                                if (Shortkey.StartsWith("ShortStatus"))
                                {
                                    ShortkeyStr.Add(Shortkey);
                                }
                            }


                            if (OpenkeyStr.Count() > 0 || ShortkeyStr.Count() > 0)
                            {
                                string openPositionStr = "";

                                foreach (string key in OpenkeyStr)
                                {

                                    bool IsOpen = false;

                                    string[] OpenKeyArr = key.Split('-');

                                    int iICID = int.Parse(OpenKeyArr[1].Replace("IC", ""));

                                    string Str = testItemResult.DicResult[key].ToString();

                                    string[] OpenStrArr = Str.Split(',');

                                    OpenStrArr = OpenStrArr.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                                    for (int i = 0; i < OpenStrArr.Length; i++)
                                    {
                                        int iStr = Convert.ToInt32((string)OpenStrArr[i].Trim(), 16);

                                        string binStr = Convert.ToString(iStr, 2).PadLeft(8, '0');

                                        int a = 0;
                                        int iCount = OpenStrArr.Length - i;

                                        foreach (char c in binStr)
                                        {
                                            int iLed = iCount * 8 - a;

                                            DIYLedModel dIYLedModel = TestStation.LedModelList.Find(x => x.ICID == iICID.ToString() && x.LEDID == iLed);

                                            if (dIYLedModel != null)
                                            {

                                                if (c == '0')
                                                {

                                                }
                                                else
                                                {
                                                    openPositionStr += "【" + (iICID + 1).ToString() + "_" + iLed.ToString() + "】" + ";";

                                                    IsOpen = true;
                                                }

                                            }

                                            a++;
                                        }


                                    }

                                    if (IsOpen)
                                    {
                                        isOpenShortFull = true;
                                        Resultdic.Add(key, testItemResult.DicResult[key].ToString());
                                    }
                                }

                                Remark += "Open:" + openPositionStr + "\r\n";

                                string shortPositionStr = "";

                                foreach (string key in ShortkeyStr)
                                {
                                    bool isShort = false;

                                    string[] ShortKeyArr = key.Split('-');

                                    int iICID = int.Parse(ShortKeyArr[1].Replace("IC", ""));

                                    string Str = testItemResult.DicResult[key].ToString();

                                    string[] ShortStrArr = Str.Split(',');

                                    ShortStrArr = ShortStrArr.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                                    for (int i = 0; i < ShortStrArr.Length; i++)
                                    {
                                        int iStr = Convert.ToInt32((string)ShortStrArr[i].Trim(), 16);

                                        string binStr = Convert.ToString(iStr, 2).PadLeft(8, '0');

                                        int a = 0;
                                        int iCount = ShortStrArr.Length - i - 1;

                                        foreach (char c in binStr)
                                        {
                                            int iLed = iCount * 8 + 8 - a;

                                            DIYLedModel dIYLedModel = TestStation.LedModelList.Find(x => x.ICID == iICID.ToString() && x.LEDID == iLed);

                                            if (dIYLedModel != null)
                                            {

                                                if (c == '0')
                                                {

                                                }
                                                else
                                                {
                                                    shortPositionStr += "【" + (iICID + 1).ToString() + "_" + iLed.ToString() + "】" + ";";

                                                    isShort = true;
                                                }

                                            }

                                            a++;
                                        }

                                    }

                                    if (isShort)
                                    {
                                        isOpenShortFull = true;
                                        Resultdic.Add(key, testItemResult.DicResult[key].ToString());
                                    }
                                }

                                Remark += "Short:" + shortPositionStr + "\r\n";

                            }

                        }
                    }

                    testItemResult.DicResult = Resultdic;
                    testItemResult.Remark = Remark;

                    if (dValue <= testItemResult.Limit.Upper && dValue >= testItemResult.Limit.Lower)
                    {

                        if (!isOpenShortFull)
                        {
                            testItemResult.ResultValue = Math.Round(dValue, 3).ToString() + "/OSPass";
                            testItemResult.Result = "Pass";
                            AppendTestData(string.Format("{0}-{1} 成功，值为：{2},Limit-Lower:{3},Upper:{4},OSPass", ">>>", testItemResult.Name, dValue, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Green);
                            return true;
                        }
                        else
                        {
                            testItemResult.ResultValue = Math.Round(dValue, 3).ToString() + "/OSFail";
                            testItemResult.Result = "Fail";
                            AppendTestData(string.Format("{0}-{1} 失败，值为：{2},Limit-Lower:{3},Upper:{4},OpenShortFail", ">>>", testItemResult.Name, dValue, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Red);
                            AppendTestData(string.Format("OpenShortFail：{0}", testItemResult.Remark), MyBrushes.Red);
                            return false;
                        }
                    }
                    else
                    {
                        if (!isOpenShortFull)
                        {
                            testItemResult.ResultValue = Math.Round(dValue, 3).ToString() + "/OSPass";
                            testItemResult.Result = "Fail";
                            AppendTestData(string.Format("{0}-{1} 失败，值为：{2},Limit-Lower:{3},Upper:{4},OSPass", ">>>", testItemResult.Name, dValue, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Red);
                            return false;
                        }
                        else
                        {
                            testItemResult.ResultValue = Math.Round(dValue, 3).ToString() + "/OSFail";
                            testItemResult.Result = "Fail";
                            AppendTestData(string.Format("{0}-{1} 失败，值为：{2},Limit-Lower:{3},Upper:{4},OpenShortFail", ">>>", testItemResult.Name, dValue, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Red);
                            return false;
                        }
                    }

                }

                if (dValue <= testItemResult.Limit.Upper && dValue >= testItemResult.Limit.Lower)
                {
                    testItemResult.ResultValue = Math.Round(dValue, 3).ToString();
                    testItemResult.Result = "Pass";
                    AppendTestData(string.Format("{0}-{1} 成功，值为：{2},Limit-Lower:{3},Upper:{4}", ">>>", testItemResult.Name, dValue, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Green);
                    return true;
                }
                else
                {
                    testItemResult.ResultValue = Math.Round(dValue, 3).ToString();
                    testItemResult.Result = "Fail";
                    AppendTestData(string.Format("{0}-{1} 失败，值为：{2},Limit-Lower:{3},Upper:{4}", ">>>", testItemResult.Name, dValue, testItemResult.Limit.Lower, testItemResult.Limit.Upper), MyBrushes.Red);
                    return false;
                }
            }
        }

        #endregion

        #region [完成测试]
        /// <summary>
        /// 完成测试
        /// </summary>
        /// <param name="isStoped">表示是否手动停止测试</param>
        private void FinishTest(bool isStoped, bool isSuccess = false)
        {
            //获取测试结果状态
            TestResultState result = isStoped ? TestResultState.Stop : isSuccess ? TestResultState.Pass : TestResultState.Fail;

            TestInfo.TestEnd(result);

            //测试结束将测试结果发送到点灯机 - AddByBandit 2024年8月27日 10:15:36
           // DLEDLightingHelper.GetTestResult(result == TestResultState.Pass);

            if (isStoped)
            {
                PowerOFFLed();

                
                TestStation.Status.Update("Test Stopped.", MyBrushes.Yellow);
            }
            else
            {
               
                TestStation.Status.Update("Test Finished", MyBrushes.RichGreen);

                if (!IsMultiStationStart)
                {
                    if (TestStation.TestInfo.StationName.Contains("NTC"))
                    {
                        WriteTestLog(result);
                        //NTC 测试完自动关灯
                        PowerOFFLed();
                    }
                }
            }

            //在这里重置USB\COM等设备是否连接
            //RelayBoardHelper.Reset();

            this.ThreadSafe(() =>
            {
                this.txtBarcode.Focus();
                this.txtBarcode.SelectAll();
            }, false);

            //TestStation.IsStop = false;


        }
        #endregion

        #region SerialPort
        /// <summary>
        /// 将json数据反序列化为Dictionary
        /// </summary>
        /// <param name="jsonData">json数据</param>
        /// <returns></returns>
        private Dictionary<string, object> JsonToDictionary(string jsonData)
        {
            jsonData = jsonData.Trim();
            //实例化JavaScriptSerializer类的新实例
            JavaScriptSerializer jss = new JavaScriptSerializer();
            try
            {
                //将指定的 JSON 字符串转换为 Dictionary<string, object> 类型的对象
                return jss.Deserialize<Dictionary<string, object>>(jsonData);
            }
            catch (Exception ex)
            {
                LogHelper.Info(ex.Message);
                return null;
            }
        }
        private void InitMiniLedLightUpSerialPort()
        {
            lock (App.DLEDLightingHelpers)
            {
                bool first = false;

                this.TestStation.DLEDLightingHelper = App.DLEDLightingHelpers.FirstOrDefault(s => s.PortName == this.TestStation.StationInfo.ComPort);

                if (this.TestStation.DLEDLightingHelper == null)
                {
                    this.TestStation.DLEDLightingHelper = new DLEDLightingHelper(this.TestStation.StationInfo.ComPort);
                    App.DLEDLightingHelpers.Add(this.TestStation.DLEDLightingHelper);

                    first = true;
                }

                if (!first)
                {

                    //this.TestStation.DLEDLightingHelper.FireOnConnectedChanged();
                    Instance_OnConnectedChanged(this.TestStation.DLEDLightingHelper, this.TestStation.DLEDLightingHelper.IsConnected);
                }
                else
                {
                    this.TestStation.DLEDLightingHelper.OnReceived += DLEDLightingHelper_OnReceived;

                    this.TestStation.DLEDLightingHelper.OnConnectedChanged += Instance_OnConnectedChanged;

                    this.TestStation.DLEDLightingHelper.OnError += (sender, e) =>
                    {
                        LogHelper.Error(e.Exception, e.Title);
                    };

                    this.TestStation.DLEDLightingHelper.Connect("\r\n", ConfigHelper.GetValueToInt("BaudRate", 1000000), 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One);
                }
            }

        }

        private void DLEDLightingHelper_OnReceived(object sender, string data)
        {
            if (data == "Stop")
            {
                if (TestStation.IsStop)
                {
                    TestStation.IsStop = false;

                    this.Loading.Show("即将结束测试");
                }
            }
            if (data == "FWReset")
            {
                if (TestStation.IsStop)
                {
                    TestStation.IsStop = false;

                    this.ShowPromptWindow($"{data},结束测试", PromptType.Red, 6);
                    AppendTestData($"{data},结束测试", MyBrushes.Red);
                    this.Loading.Show($"即将结束测试");

                    //this.DLEDLightingHelper.BanditSerialPort.Close();
                    //this.DLEDLightingHelper.BanditSerialPort.Open();
                }
                LogHelper.Info("关闭串口 ");
                this.DLEDLightingHelper.BanditSerialPort.Close();
            }
        }

        private void Instance_OnConnectedChanged(DeviceBase sender, bool isConnect)
        { 
            UpdateStartButtonState(isConnect);

            if (isConnect)
            {
                Thread.Sleep(1000);

                if (App.SettingViewModel.Setting.IsSendHeartBeat)
                {
                    LogHelper.Info("发送心跳包开始");
                    DLEDLightingHelper.SetRS232ConStart();
                }
            }

        }
        #endregion

        #region 当设备连接或断开后更新开始测试按钮的状态
        private void UpdateStartButtonState(bool IsConnect)
        {
            if (this.TestStation != null)
            {
                if (this.TestStation != null && this.TestStation.TestInfo != null)
                {

                    TestInfo.EnabledStartButton = IsConnect; //RelayBoardHelper.RelayBoards.All(s => s.IsConnect) && this._Meter.IsConnected;

                    if (TestInfo.EnabledStartButton)
                    {
                        this.TestStation.Status.Update("Ready", MyBrushes.White);
                        //this.TestStation.SerialStatus.Update("Serial Connected", MyBrushes.Green);
                        this.TestStation.SerialStatus.Update(string.Format("[{0}] is connected!", this.TestStation.StationInfo.ComPort), MyBrushes.Green);
                    }
                    else
                    {
                        if (TestStation.IsStop)
                        {
                            TestStation.IsStop = false;
                            this.Loading.Show("串口断开，程序即将暂停");
                            this.ShowPromptWindow("串口断开，程序即将暂停", PromptType.Red);
                        }
                        this.TestStation.Status.Update("Wating...", MyBrushes.RichRed);
                        //this.TestStation.SerialStatus.Update("Serial DisConnect", MyBrushes.Red);
                        this.TestStation.SerialStatus.Update(string.Format("[{0}] is not connected!", this.TestStation.StationInfo.ComPort), MyBrushes.Red);
                    }
                }
            }
        }
        #endregion

        #region 追加测试信息
        private Block AppendTestData(string data, MyBrushes statusBrush)
        {
            Block block = null;

            if (this.Dispatcher.Thread == System.Threading.Thread.CurrentThread)
            {
                block = GetBlock(data, statusBrush);

                this.rtxtTestData.Document.Blocks.Add(block);
            }
            else
            {
                this.Dispatcher.Invoke((Action)delegate
                {
                    block = AppendTestData(data, statusBrush);
                });
            }

            return block;
        }

        private Block GetBlock(string data, MyBrushes statusBrush)
        {
            Inline inline = new Run(data);

            inline.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(statusBrush.ToBrushString()));

            return new Paragraph(inline) { LineHeight = 1.0 };
        }

        private void rtxtTestData_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.rtxtTestData.ScrollToEnd();
        }
        #endregion

        #region 测试Log记录

        private void WriteTestLog1(TestResultState result)
        {
            try
            {
                #region CSV Combine Define

                string collectHeader = string.Format("SerialNumber,overallResult");//,startTime,endTime,testTime");

                string collectData = string.Format("{0},{1}",
                                         TestInfo.Barcode,
                                         result.ToString().ToUpper());
                //,
                //ViewModel.TestInfo.TestTimer.StartTime.ToString("yyyy/MM/dd HH:mm:ss"),
                //ViewModel.TestInfo.TestTimer.EndTime.ToString("yyyy/MM/dd HH:mm:ss"),
                //ViewModel.TestInfo.TestTimer.TestTime);

                foreach (TestItemResult testItemResult in TestInfo.TestItemResults)
                {
                    if (testItemResult.Result == "None" || testItemResult.Result == "" || !testItemResult.IsTest)
                    {
                        continue;
                    }

                    collectHeader += "," + testItemResult.Name;

                    collectData += "," + testItemResult.Result;

                }

                collectHeader += ",startTime,endTime,testTime";
                collectData += "," + TestInfo.TestTimer.StartTime.ToString("yyyy/MM/dd HH:mm:ss") + "," + TestInfo.TestTimer.EndTime.ToString("yyyy/MM/dd HH:mm:ss") + "," + TestInfo.TestTimer.TestTime;


                #endregion

                if (!string.IsNullOrWhiteSpace(TestInfo.Barcode))
                {
                    string saveDir = string.Format(@"{0}TestLog\{1}\{2}\{3}\", this.GetBaseDirectory(), ConfigInfo.TestConfig.Project, DateTime.Now.ToString("yyyy-MM-dd"), result.ToString().ToUpper());
                    if (!System.IO.Directory.Exists(saveDir))
                    {
                        System.IO.Directory.CreateDirectory(saveDir);
                    }

                    string logFileName = saveDir + string.Format(@"{0}_{1}_{2}_{3}_{4}.csv", result.ToString().ToUpper(), TestInfo.Barcode, ConfigInfo.TestConfig.Project, ConfigInfo.TestConfig.Station, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));

                    string csvFileName = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(saveDir)) + string.Format(@"\Combine-{0}-{1}-{2}.csv", ConfigInfo.TestConfig.Project, ConfigInfo.TestConfig.Station, DateTime.Now.ToString("yyyy-MM-dd"));

                    bool isExists = System.IO.File.Exists(csvFileName);

                    StringBuilder sbCsv = new StringBuilder();
                    if (!isExists)
                    {
                        TestCodeModel testCodeModel = TestStation.ConfigInfo.TestConfig.TestCodeModels.First(s => s.TestModelCode == (int)ConfigInfo.TestConfig.TestModelCode);

                        sbCsv.AppendLine(string.Format("{0} V{1}", this.GetAssemblyName(), this.GetVersion()));
                        sbCsv.AppendLine("Project, " + ConfigInfo.TestConfig.Project + "," + testCodeModel.Name);
                        sbCsv.AppendLine("Station, " + ConfigInfo.TestConfig.Station);
                        sbCsv.AppendLine(collectHeader);

                    }

                    sbCsv.AppendLine(collectData);

                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(logFileName, false, Encoding.UTF8))
                    {
                        StringBuilder sbLog = new StringBuilder();
                        sbLog.AppendLine(string.Format("{0} V{1}", this.GetAssemblyName(), this.GetVersion()));
                        sbLog.AppendLine("Project, " + ConfigInfo.TestConfig.Project);
                        sbLog.AppendLine("Station, " + ConfigInfo.TestConfig.Station);

                        sbLog.AppendLine(collectHeader);

                        sbLog.AppendLine(collectData);



                        sbLog.AppendLine("TestNum,TestName,IsTest,Result,ResultValue");

                        foreach (TestItemResult testItemResult in TestInfo.TestItemResults)
                        {

                            string testData = string.Empty;

                            testData += testItemResult.Num.ToString() + "," + testItemResult.Name + "," + testItemResult.IsTest.ToString();

                            if (testItemResult.IsTest)
                            {
                                testData += "," + testItemResult.Result + "," + testItemResult.ResultValue.Replace(",", ";");

                                if (testItemResult.DicResult != null && testItemResult.TestItemCode != "QiPanPattenDisplay" && testItemResult.TestItemCode != "DIYPattenDisplay")
                                {
                                    foreach (var dic in testItemResult.DicResult)
                                    {
                                        if (dic.Key.StartsWith("CMD") || dic.Key.StartsWith("result"))
                                        {
                                            continue;
                                        }

                                        testData += "," + dic.Key + "," + dic.Value.ToString().Replace(",", ":");
                                    }
                                }
                            }

                            sbLog.AppendLine(testData);

                        }

                        sw.Write(sbLog.ToString());
                        sw.Close();
                    }

                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(csvFileName, true, Encoding.UTF8))
                    {
                        sw.Write(sbCsv.ToString());
                        sw.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex, "WriteTestLog");
            }
        }

        private void WriteTestLog(TestResultState result)
        {
            try
            {
                #region CSV Combine Define

                string collectHeader = string.Format("Date,Model,Barcode,Result");//,startTime,endTime,testTime");

                string collectData = string.Format("{0},{1},{2},{3}",
                                         TestInfo.TestTimer.EndTime.ToString("yyyy/MM/dd HH:mm:ss"),
                                         //ConfigInfo.TestConfig.TestCodeModels.FirstOrDefault(x=>x.TestModelCode == ConfigInfo.TestConfig.TestModelCode).Name ,
                                         ConfigInfo.TestConfig.Project,
                                         TestInfo.Barcode,
                                         result.ToString().ToUpper());

                foreach (TestItemResult testItemResult in TestInfo.TestItemResults)
                {
                    if (testItemResult.TestItemCode == "ThermistorTestingRoomTemperature"|| testItemResult.TestItemCode == "ThermistorTestingLightingTemperature")
                    {
                        collectHeader += "," + ConfigHelper.GetVauleToString(testItemResult.Name,"Test") + "1";
                        collectHeader += "," + ConfigHelper.GetVauleToString(testItemResult.Name,"Test") + "2";

                        string[] NtcStr = testItemResult.ResultValue.Split(";");

                        if (NtcStr.Count() == 2)
                        {
                            collectData += "," + NtcStr[0];
                            collectData += "," + NtcStr[1];
                        }
                        else
                        {
                            collectData += "," + testItemResult.ResultValue;
                            collectData += "," + "";
                        }
                    }
                    else
                    {
                        collectHeader += "," + ConfigHelper.GetVauleToString(testItemResult.Name, "Test");
                        collectData += "," + testItemResult.ResultValue;
                    }

                }

                #endregion

                if (!string.IsNullOrWhiteSpace(TestInfo.Barcode))
                {
                    string saveDir = string.Format(@"{0}TestLog\{1}\", this.GetBaseDirectory(), DateTime.Now.ToString("yyyy-MM-dd"));

                    string saveDetailDir = string.Format(@"{0}DetailTestLog\{1}\{2}\{3}\", this.GetBaseDirectory(), ConfigInfo.TestConfig.Project, DateTime.Now.ToString("yyyy-MM-dd"), result.ToString().ToUpper());

                    if (!System.IO.Directory.Exists(saveDir))
                    {
                        System.IO.Directory.CreateDirectory(saveDir);
                    }

                    if (!System.IO.Directory.Exists(saveDetailDir))
                    {
                        System.IO.Directory.CreateDirectory(saveDetailDir);
                    }
                    
                    LogHelper.Info("3["+ TestInfo.Barcode+"]");

                    string logFileName = saveDetailDir + string.Format(@"{0}_{1}_{2}_{3}_{4}.csv", result.ToString().ToUpper(), TestInfo.Barcode, ConfigInfo.TestConfig.Project, ConfigInfo.TestConfig.Station, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));

                    string csvFileName = saveDir + string.Format(@"\Combine-{0}.csv", DateTime.Now.ToString("yyyy-MM-dd"));

                    bool isExists = System.IO.File.Exists(csvFileName);

                    TestCodeModel testCodeModel = TestStation.ConfigInfo.TestConfig.TestCodeModels.First(s => s.TestModelCode == (int)ConfigInfo.TestConfig.TestModelCode);

                    StringBuilder sbCsv = new StringBuilder();
                    if (!isExists)
                    {
                        sbCsv.AppendLine(collectHeader);
                    }

                    sbCsv.AppendLine(collectData);

                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(logFileName, false, Encoding.UTF8))
                    {
                        LogHelper.Info("4[" + TestInfo.Barcode + "]");
                        StringBuilder sbLog = new StringBuilder();
                        sbLog.AppendLine(string.Format("{0} V{1}", this.GetAssemblyName(), this.GetVersion()));
                        sbLog.AppendLine("Project, " + ConfigInfo.TestConfig.Project + "," + testCodeModel.Name);
                        sbLog.AppendLine("Station, " + ConfigInfo.TestConfig.Station);

                        sbLog.AppendLine(collectHeader);

                        sbLog.AppendLine(collectData);

                        sbLog.AppendLine("TestNum,TestName,IsTest,Lower,Upper,Result,ResultValue");

                        foreach (TestItemResult testItemResult in TestInfo.TestItemResults)
                        {

                            string testData = string.Empty;

                            testData += testItemResult.Num.ToString() + "," + testItemResult.Name + "," + testItemResult.IsTest.ToString();

                            if (testItemResult.IsTest)
                            {
                                testData += "," + testItemResult.Limit.Lower + "," + testItemResult.Limit.Upper + "," + testItemResult.Result + "," + testItemResult.ResultValue.Replace(",", ";");

                                if (testItemResult.DicResult != null && testItemResult.TestItemCode != "QiPanPattenDisplay" && testItemResult.TestItemCode != "DIYPattenDisplay")
                                {

                                    foreach (var dic in testItemResult.DicResult)
                                    {
                                        if (dic.Key.StartsWith("CMD") || dic.Key.StartsWith("result"))
                                        {
                                            continue;
                                        }

                                        testData += "," + dic.Key + "," + dic.Value.ToString().Replace(",", ":");
                                    }
                                }
                            }

                            sbLog.AppendLine(testData);

                        }

                        sw.Write(sbLog.ToString());
                        sw.Close();
                    }

                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(csvFileName, true, Encoding.UTF8))
                    {
                        sw.Write(sbCsv.ToString());
                        sw.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex, "WriteTestLog");
            }
        }

        #endregion

        //EditByBandit 2024年4月25日 14:05:20
        private bool SetModel()
        {
            #region Model 设置

            int code = ConfigInfo.TestConfig.TestModelCode < 100 ? ConfigInfo.TestConfig.TestModelCode : int.Parse(ConfigInfo.TestConfig.TestModelCode.ToString().Substring(2));

            AppendTestData(string.Format("Model设置Case : {0}", code), MyBrushes.Yellow);

            if (!DLEDLightingHelper.SetCaseCode(code))
            {
                AppendTestData("Model设置失败", MyBrushes.Red);

                return false;
            }
            else
            {
                AppendTestData("Model设置成功", MyBrushes.Green);
                Thread.Sleep(10);
            }

            if (ConfigInfo.TestConfig.IsPwmModeSet)
            {
                AppendTestData(string.Format("PWM Mode设置 : {0}", ConfigInfo.TestConfig.PwnModeCode), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetPWMMode(ConfigInfo.TestConfig.PwnModeCode))
                {
                    AppendTestData("PWM Mode设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("PWM Mode设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }

            if (ConfigInfo.TestConfig.IsVLedSet)
            {
                AppendTestData(string.Format("VLED设置 : {0}", ConfigInfo.TestConfig.DvledValue), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetVBL(ConfigInfo.TestConfig.DvledValue))
                {
                    AppendTestData("VLED设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("VLED设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }

            if (ConfigInfo.TestConfig.IsOCPOVPSet)
            {
                AppendTestData(string.Format("过压过流设置 : {0},{1},{2},{3}", ConfigInfo.TestConfig.DvLedOvpValue, ConfigInfo.TestConfig.DvLedOcpValue, ConfigInfo.TestConfig.DICOvpValue, ConfigInfo.TestConfig.DICOcpValue * 1000), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetOCPOVP(ConfigInfo.TestConfig.DvLedOvpValue, ConfigInfo.TestConfig.DvLedOcpValue, ConfigInfo.TestConfig.DICOvpValue, ConfigInfo.TestConfig.DICOcpValue * 1000))
                {
                    AppendTestData("过压过流设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("过压过流设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }

            if (ConfigInfo.TestConfig.IsMCSet)
            {
                AppendTestData(string.Format("MC设置 : {0}", ConfigInfo.TestConfig.IMCValue), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetMC(ConfigInfo.TestConfig.IMCValue))
                {
                    AppendTestData("MC设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("MC设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }

            if (ConfigInfo.TestConfig.IsDCSet)
            {
                AppendTestData(string.Format("DC设置 : {0}", ConfigInfo.TestConfig.IDCValue), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetDC(ConfigInfo.TestConfig.IDCValue))
                {
                    AppendTestData("DC设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("DC设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }

            if (ConfigInfo.TestConfig.IsBCSet)
            {
                AppendTestData(string.Format("BC设置 : {0}", ConfigInfo.TestConfig.IBCValue), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetBC(ConfigInfo.TestConfig.IBCValue))
                {
                    AppendTestData("BC设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("BC设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }

            if (ConfigInfo.TestConfig.IsScaleSet)
            {
                AppendTestData(string.Format("Scale设置 : {0}", ConfigInfo.TestConfig.IScaleValue), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetSCALE(ConfigInfo.TestConfig.IScaleValue))
                {
                    AppendTestData("Scale设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("Scale设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }

            if (ConfigInfo.TestConfig.IsILEDSet)
            {
                AppendTestData(string.Format("ILED设置 : {0}", ConfigInfo.TestConfig.IILEDValue), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetILED(ConfigInfo.TestConfig.IILEDValue))
                {
                    AppendTestData("ILED设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("ILED设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }

            if (ConfigInfo.TestConfig.IsSRCSet)
            {
                AppendTestData(string.Format("SRC设置 : {0}", ConfigInfo.TestConfig.ISrcValue), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetSRC(ConfigInfo.TestConfig.ISrcValue))
                {
                    AppendTestData("SRC设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("SRC设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }

            if (ConfigInfo.TestConfig.IsLEDNUMSet)
            {
                AppendTestData(string.Format("LEDNUM设置 : {0}", ConfigInfo.TestConfig.ILEDNUMValue), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetLEDNUM(ConfigInfo.TestConfig.ILEDNUMValue))
                {
                    AppendTestData("LEDNUM设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("LEDNUM设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }


            if (ConfigInfo.TestConfig.IsRSETSet)
            {
                AppendTestData(string.Format("RSET设置 : {0}", ConfigInfo.TestConfig.IRSETValue), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetRSET(ConfigInfo.TestConfig.IRSETValue))
                {
                    AppendTestData("RSET设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("RSET设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }


            if (ConfigInfo.TestConfig.IsCLKSet)
            {
                AppendTestData(string.Format("CLK设置 : {0}", ConfigInfo.TestConfig.ICLKValue), MyBrushes.Yellow);
                if (!DLEDLightingHelper.SetCLK(ConfigInfo.TestConfig.ICLKValue))
                {
                    AppendTestData("CLK设置失败", MyBrushes.Red);

                    return false;
                }
                else
                {
                    AppendTestData("CLK设置成功", MyBrushes.Green);
                    Thread.Sleep(10);
                }
            }

            return true;

            #endregion
        }
    }
}
